Beginners Digest, Vol 172, Issue 1

2023-12-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Prime number test performance on negativeintegers
  (Folsk Pratima)
   2. Re:  Prime number test performance on negative integers
  (Francesco Ariis)
   3. Re:  Prime number test performance on negative integers
  (Folsk Pratima)
   4. Re:  Prime number test performance on negative integers
  (Francesco Ariis)
   5. Re:  Prime number test performance on negative integers
  (Folsk Pratima)
   6. Re:  Prime number test performance on negative integers
  (Francesco Ariis)


--

Message: 1
Date: Mon, 11 Dec 2023 19:24:17 +0200
From: Folsk Pratima 
To: beginners@haskell.org
Subject: [Haskell-beginners] Prime number test performance on negative
integers
Message-ID: <20231211192417.12af6...@folsk0pratima.cock.li>
Content-Type: text/plain; charset=US-ASCII

Please explain why this fails for negative numbers. By fails I mean it
starts eating RAM infinitely until either me or OOM kills it. If you
replace `m1` definition with the one commented out, the code will fail
for positive integers as well, which is very frustrating.

import System.Environment

isPrime :: Int -> (Bool, String)
isPrime n =
let ll n = k + 1 : k + 5 : ll (n + 1)
  where
k = 6 * n + 1
l = 2 : 3 : 5 : ll 1
q (i:is)
| i * i > n = (True, "it is")
| (n `rem` i) == 0 = (False, "divisible by " ++ show i)
| otherwise = q is
 in q l

main =
getArgs >>= \argv ->
let f True = "primal"
f False = "not primal"
m0 = map (\x -> read x :: Int) argv
m1 = m0
--m1 =
--map
--(\x ->
-- if x < 0
-- then -x
-- else x)
--m0
m2 = map isPrime m1
msg (x, (y0, y1)) = x ++ " is " ++ f y0 ++ " because " ++ y1
 in mapM_ putStrLn $ map msg (zip argv m2)


--

Message: 2
Date: Mon, 11 Dec 2023 18:55:21 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Prime number test performance on
negative integers
Message-ID: 
Content-Type: text/plain; charset=utf-8

Hello Pratima,

Il 11 dicembre 2023 alle 19:24 Folsk Pratima ha scritto:
> Please explain why this fails for negative numbers. By fails I mean it
> starts eating RAM infinitely until either me or OOM kills it. If you
> replace `m1` definition with the one commented out, the code will fail
> for positive integers as well, which is very frustrating.

I have replaced m1 definition with the commented one, and it works on
my machine.

f@x270:/tmp/prova$ ./prime -4
-4 is not primal because divisible by 2

How are you invoking the program?

A few additional notes (run `hlint` for more)

> main =
> getArgs >>= \argv ->

I don’t mind `>>=` but with `do` notation and `traceM/traceShowM` it
is easier to debug your programs.

> --m1 =
> --map
> --(\x ->
> -- if x < 0
> -- then -x
> -- else x)
> --m0

More compact: `m1 = map abs m0`

> msg (x, (y0, y1)) = x ++ " is " ++ f y0 ++ " because " ++ y1

Ancillary functions like this one can go in the `where` section.
Ciao
—F



--

Message: 3
Date: Mon, 11 Dec 2023 20:24:13 +0200
From: Folsk Pratima 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Prime number test performance on
negative integers
Message-ID: <20231211202413.576b0...@folsk0pratima.cock.li>
Content-Type: text/plain; charset=UTF-8

>Hello Pratima,
>
>Il 11 dicembre 2023 alle 19:24 Folsk Pratima ha scritto:
>> Please explain why this fails for negative numbers. By fails I mean
>> it starts eating RAM infinitely until either me or OOM kills it. If
>> you replace `m1` definition with the one commented out, the code will
>> fail for positive integers as well, which is very frustrating.
>
>I have replaced m1 definition with the commented one, and it works on
>my machine.
>
>f at x270:/tmp/prova$ ./prime -4
>-4 is not primal because divisible by 2
>
>How are you invoking the program?
>
>A few additional notes (run `hlint` for more)
>
>> main =
>> getArgs >>= \argv ->
>
>I don’t mind `>>=` but with `do` notation and 

Beginners Digest, Vol 171, Issue 2

2023-09-13 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Beginner question. (brad73435 Smith)


--

Message: 1
Date: Tue, 12 Sep 2023 06:35:14 -0700
From: brad73435 Smith 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Beginner question.
Message-ID: <8e4007fd-fb45-43d8-9aa9-324f6c4c2...@gmail.com>
Content-Type: text/plain; charset=utf-8

That’s an impressive step in complexity!

FWIW, for ‘f x y = x <> " " <> y’ that website gave the same result as the 
book… ‘f = (<>) . (<> " ")’… so it seems to do a good job of giving a 
simplified solution. 

Understood re only using point-free for simple, clear cases… though it was a 
good exercise for me to understand what’s going on with the function 
composition operator (.).

Thank you!
Brad

Sent from my iPhone

> On Sep 12, 2023, at 1:08 AM, Sylvain Henry  wrote:
> 
> Hi,
> 
> https://pointfree.io/ gives:
> 
> Input: f x y z = x <> " " <> y <> " " <> z
> 
> Output: f = ((<>) .) . flip flip " " . ((<>) .) . (<>) . (<> " ")
> 
> So no, it's not something simple!
> 
> For clarity I would recommend using the non-point-free version, even in the 
> case given in the book. Use point-free only in simple cases like `map (+ 1)` 
> where the meaning is obvious.
> 
> Sylvain
> 
> 
>> On 12/09/2023 02:45, Brad Smith wrote:
>> I just started working my way through a Haskell book... first time with 
>> functional programming. Mid way through the first chapter she's introducing 
>> point-free programming with a trivial example transitioning from not 
>> point-free...
>> 
>> makeGreeting salutation person = salutation <> " " <> person
>> 
>> to point free...
>> 
>> makeGreeting' = (<>) . (<> " ")
>> 
>> After a little playing with it... it seems to make sense. So I thought I'd 
>> try evolving from salutation and name to salutation, first, and last names. 
>> But, after a bit of tinkering, I haven't been able to make it work...
>> 
>> I'm sure it's something simple (one way or the other)... any help would be 
>> appreciated!
>> 
>> Brad
>> 
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 171, Issue 2
*


Beginners Digest, Vol 171, Issue 1

2023-09-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Beginner question. (Brad Smith)
   2. Re:  Beginner question. (Sylvain Henry)


--

Message: 1
Date: Mon, 11 Sep 2023 17:45:43 -0700
From: Brad Smith 
To: beginners@haskell.org
Subject: [Haskell-beginners] Beginner question.
Message-ID:

Content-Type: text/plain; charset="utf-8"

I just started working my way through a Haskell book... first time with
functional programming. Mid way through the first chapter she's
introducing point-free programming with a trivial example transitioning
from not point-free...

makeGreeting salutation person = salutation <> " " <> person

to point free...

makeGreeting' = (<>) . (<> " ")

After a little playing with it... it seems to make sense. So I thought I'd
try evolving from salutation and name to salutation, first, and last names.
But, after a bit of tinkering, I haven't been able to make it work...

I'm sure it's something simple (one way or the other)... any help would be
appreciated!

Brad
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 12 Sep 2023 10:07:42 +0200
From: Sylvain Henry 
To: 
Subject: Re: [Haskell-beginners] Beginner question.
Message-ID: 
Content-Type: text/plain; charset="UTF-8"; format=flowed

Hi,

https://pointfree.io/ gives:

Input: f x y z = x <> " " <> y <> " " <> z

Output: f = ((<>) .) . flip flip " " . ((<>) .) . (<>) . (<> " ")

So no, it's not something simple!

For clarity I would recommend using the non-point-free version, even in 
the case given in the book. Use point-free only in simple cases like 
`map (+ 1)` where the meaning is obvious.

Sylvain


On 12/09/2023 02:45, Brad Smith wrote:
> I just started working my way through a Haskell book... first time 
> with functional programming. Mid way through the first chapter she's 
> introducing point-free programming with a trivial example 
> transitioning from not point-free...
>
> makeGreeting salutation person = salutation <> " " <> person
>
> to point free...
>
> makeGreeting' = (<>) . (<> " ")
>
> After a little playing with it... it seems to make sense. So I thought 
> I'd try evolving from salutation and name to salutation, first, and 
> last names. But, after a bit of tinkering, I haven't been able to make 
> it work...
>
> I'm sure it's something simple (one way or the other)... any help 
> would be appreciated!
>
> Brad
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 171, Issue 1
*


Beginners Digest, Vol 170, Issue 2

2023-03-04 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Show encoded string of JWT / Crypto.JWT (Pietro Grandinetti)
   2. Re:  Show encoded string of JWT / Crypto.JWT (Pietro Grandinetti)


--

Message: 1
Date: Sat, 4 Mar 2023 14:43:06 +
From: Pietro Grandinetti 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Show encoded string of JWT / Crypto.JWT
Message-ID:



Content-Type: text/plain; charset="iso-8859-1"

Hello-

I am working with this package:
I created a `SignedJWT` object, but cannot find a way to print it in the 
standard string form. I mean the string that would be used by clients, for 
example to send it in the "Authorization: Bearer ..." header of a HTTP request. 
Like this one: 
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"

ghci> jwt <- ... -- some code
ghci> :t jwt
jwt :: Either JWTError SignedJWT
ghci> show jwt
"Right JWS Base64Octets 
\"{\\\"aud\\\":\\\"bob\\\",\\\"iat\\\":1.677940566501089259e9,\\\"iss\\\":\\\"alice\\\"}\"
 Identity (Signature Nothing (JWSHeader {_jwsHeaderAlg = HeaderParam () PS512, 
_jwsHeaderJku = Nothing, _jwsHeaderJwk = Nothing, _jwsHeaderKid = Nothing, 
_jwsHeaderX5u = Nothing, _jwsHeaderX5c = Nothing, _jwsHeaderX5t = Nothing, 
_jwsHeaderX5tS256 = Nothing, _jwsHeaderTyp = Nothing, _jwsHeaderCty = Nothing, 
_jwsHeaderCrit = Nothing}) (Base64Octets 
\"\\DC2\\DC4\\151`\\131\\229j\\SI,\\178-\\CAN\\191UV-\\191u\\160\\217\\NAK\\247a\\150\\159\\195\\141=\\176\\212\\197\\209\\&8u+\\SIn\\DLE]\\167\\153\\SO\\142t\\163^\\EMW\\NAKt\\252\\b\\142j\\209^\\169j\\180
 
/U*^\\184\\t\\ESC\\DC4:\\DC4\\191\\150\\150\\192\\145\\FS\\172W!\\197\\190\\193\\RSx\\216\\244\\188\\168\\141\\213|\\EM\\174\\219\\230\\130b\\157\\130:\\b)\\n\\158\\169\\228?\\179\\177\\188\\234[N3\\ETX\\162\\230C\\167\\130V'V\\246\\240\\193\\243@\\SYN\\GS\\228\\157\\248\\161{\\131\\204=fI\\SYN\\GSZ\\149\\&8\\139\\a\\153\\a3\\nt\\185\\222\\&4\\FS\\EM\\171\\NUL2\\GS\\211,8CE(\\230\\240j\\150\\253\\204\\255\\188\\141\\250-:\\ESCx;3\\163K7\\137>\\145\\&0\\186\\194U0;\\b\\206\\221)C\\SOHX\\233?\\160\\168VqY\\160\\218\\&1\\224v\\f\\215[\\n\\231\\243a>\\212\\241\\237b\\138\\251eb\\207\\217\\t\\NUL\\138\\DC3\\184\\142I\\132\\154\\213\\139\\171\\137\\214\\ETX\\250\\198xn\\GS\\137\\182\\161b\\183\\f\\195\\231(\\202\\196\\177\\SI\\222\\193\\245Dv\\199\\156\\239D\\181.\\189\\153\\EOT\\SUB\\158\\160x\\135\\169$\\226\\DC3\\132\\198\\204$\\229\\&2ZTaG\\168\\203\\188\\v\\250\\SI\\214\\176;xkx\\170C\\DLE\\228\\NULc\\200r-\\205z\\243\\246\\NUL\\212Qx\\DLE!\\182\\188^\\STX\\244@\\252\\SI\\253_L\\165\\128g\\136\\197\\NUL\\201Cb\\vm\\238_>}F6\\193[As\\v\\222\\209\\146\\206\\215\\174\\&9\\NAK`E\\253\\199\\237\\236'\\149o9\\141\\130\\138\\DEL;\\NAK\\ESC\\225\\189\\170\\&1\\SUB\\CAN\\178U\\ETBL\\216G\\251\\218\\137\\191\\SYN\\193(\\DC4q\\196T\\174>@y\\198\\&4R\\138\\155~H\\DEL\\135\\202\\236\\&0\\219\\136r\\ETX\\138\\174js\\192^\\238\\193L\\204|x\\170\\140B\\158\\f\\164>2\\166\\156*W\\130\\160*\\230a\\DC3\\173m'\\DELm\\FSS[?6\\206\\170\\ESC\\145MKS=\\164Ec0\\EM\\177\\&4whq\\194\\ACKM\\147\\210\\183\\228\\161\\136\\162{\\166\\226\\174g\\241\\210\\223b\\190\\&5\\229\\212\"))"

-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sat, 4 Mar 2023 14:46:13 +
From: Pietro Grandinetti 
To: "beginners@haskell.org" 
Subject: Re: [Haskell-beginners] Show encoded string of JWT /
Crypto.JWT
Message-ID:



Content-Type: text/plain; charset="utf-8"

Apologies, forgot to link the package: 
https://hackage.haskell.org/package/jose-0.10/docs/Crypto-JWT.html#t:SignedJWT

From: Beginners  on behalf of Pietro Grandinetti 

Sent: Saturday, March 4, 2023 3:43 PM
To: beginners@haskell.org 
Subject: [Haskell-beginners] Show encoded string of JWT / Crypto.JWT

Hello-

I am working with this package:
I created a `SignedJWT` object, but cannot find a way to print it in the 
standard string form. I mean the string that would be used by clients, for 
example to send it in the "Authorization: Bearer ..." header of a HTTP request. 
Like this one: 

Beginners Digest, Vol 170, Issue 1

2023-03-01 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Understanding reason for Monad (Pietro Grandinetti)
   2. Re:  Understanding reason for Monad (Travis Cardwell)


--

Message: 1
Date: Tue, 28 Feb 2023 14:01:15 +
From: Pietro Grandinetti 
To: Travis Cardwell , The
Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Understanding reason for Monad
Message-ID:



Content-Type: text/plain; charset="iso-8859-1"

Travis,

Thank you very much. I have a question about the `putLanguage` function below.




module Main (main) where

-- https://hackage.haskell.org/package/base
import Control.Monad.IO.Class (MonadIO(liftIO))
import Data.Bool (bool)
import System.Environment (getArgs)

-- https://hackage.haskell.org/package/transformers
import Control.Monad.Trans.Reader (ReaderT(runReaderT), asks)

data Locale = En | It

class HasLocale a where
  getLocale :: a -> Locale

instance HasLocale Locale where
  getLocale = id

class MonadLocale m where
  askLocale :: m Locale

instance (HasLocale r, Monad m) => MonadLocale (ReaderT r m) where
  askLocale = asks getLocale

putLanguage :: (MonadIO m, MonadLocale m) => m ()
putLanguage = do
locale <- askLocale
liftIO . putStrLn $ case locale of
  En -> "English"
  It -> "Italiano"

I understand that the result type, in this case `MonadLocale m => m ()`, 
determines in what context the function `askLocale` is resolved. But what would 
happen if the function type was

putLanguage' :: (MonadOut m, MonadIn v) => v () -> m () -- both MonadOut and 
MonadIn are instances of MonadLocale
putLanguage' = do
locale <- askLocale
... -- other things

which `askLocale` function would be used?

putHelloWorld :: (MonadIO m, MonadLocale m) => m ()
putHelloWorld = do
locale  <- askLocale
liftIO . putStrLn $ case locale of
  En -> "Hello world!"
  It -> "Ciao mondo!"

app :: (MonadIO m, MonadLocale m) => m ()
app = do
putLanguage
putHelloWorld

main :: IO ()
main = do
locale <- bool En It . elem "--it" <$> getArgs
runReaderT app locale

In this example, the state/context is simply a `Locale` value, which
defaults to `En`.  The `main` function checks if string `--it` is passed
as an argument and configures the locale to `It` in that case.

The final line runs the `app` function using a `ReaderT` monad
transformer with the locale as the "environment."  The `app` function,
as well as all functions that it calls in the same monad, have access to
this environment.

Type class `HasLocale` just provides a `getLocale` function for getting
a `Locale` value from some possibly larger value.  The instance is the
trivial case of `Locale` itself.

Type class `MonadLocale` provides a locale API, just `askLocale` in this
case.  In a monad that implements `MonadLocale`, the `askLocale`
function is able to get the locale.  The instance provides a way to do
this in a Reader monad that has an environment with a `HasLocale`
instance.  In this minimal example, the Reader environment is a `Locale`
value, so that trivial `HasLocale` instance is used.

The remaining three functions implement the example application.  They
do not specify a concrete monad; they instead specify constraints on the
monad, allowing them to run in any monad that meets those constraints.
The `MonadIO m` constraint is required to use `liftIO . putStrLn` in
order to print to the screen, and the `MonadLocale m` constraint is
required to get the configured locale.  In this example, they are run
in concrete monad `ReaderT Locale IO`, but note that they could also be
run in different monads as long as the constraints are satisfied.

The `app` function calls `putLanguage` and then `putHelloWorld`, and
both of these functions are able to use `askLocale` to get the
configured locale.

$ minimal-context
English
Hello world!
$ minimal-context --it
Italiano
Ciao mondo!

The architecture/design of a project/program depends on the needs.  In
some programs, explicitly passing context as arguments is the best
approach.  In others, even `MonadIO` should be avoided, since `IO` makes
anything possible.  Getting back to your original question, the use of
type classes 

Beginners Digest, Vol 169, Issue 7

2023-02-27 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Reproduce example in Crypto.JWT (Pietro Grandinetti)
   2. Re:  Understanding reason for Monad (Travis Cardwell)


--

Message: 1
Date: Sun, 26 Feb 2023 14:11:15 +
From: Pietro Grandinetti 
To: "beginners@haskell.org" 
Subject: Re: [Haskell-beginners] Reproduce example in Crypto.JWT
Message-ID:



Content-Type: text/plain; charset="windows-1252"

Francesco,

That solved it. Would it be better to use nightly only for this package and, if 
so, is this possible within the package.yaml file?

Thanks.


From: Beginners  on behalf of Francesco Ariis 

Sent: Sunday, February 26, 2023 1:05 PM
To: beginners@haskell.org 
Subject: Re: [Haskell-beginners] Reproduce example in Crypto.JWT

Il 26 febbraio 2023 alle 11:57 Pietro Grandinetti ha scritto:
> Francesco,
>
> Thanks.
> I am using stack and the version doesn't match: `stack ls dependencies` shows 
> `jose 0.9`. I can't seem to find a way to upgrade it even if I set `jose >= 
> 0.10` in the package.yaml file:

This is `jose` in stackage:

https://www.stackage.org/lts-20.12/package/jose-0.9

So switching to Nightly will do
—F
___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Mon, 27 Feb 2023 20:53:28 +0900
From: Travis Cardwell 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Understanding reason for Monad
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Hi Pietro,

The example in my previous message is that of a web application where
the user registration request handler needs to write to a database as
well as perform logging.  In a production server, connecting to a
database usually requires some configuration, and a pool of database
connections is kept open and reused for improved performance.
Similarly, logging may require configuration that the whole application
needs to use in order to log consistently, and a resource may be kept
open depending on how logging is configured.  The server can initialize
this state and provide it to various components such as request
handlers.  This state is what I referred to as a "context."  It can be
passed explicitly as arguments, but there are various other ways to
manage it.

For example, one popular design is to use a "Reader" monad, which
essentially passes the state as an implicit argument to all functions
that use the monad.  Type classes such as `MonadDatabase` or
`MonadLogger` may provide database and logging APIs utilizing the state
made available by the Reader.

Providing a meaningful minimal example is difficult because this type
of abstraction is most beneficial in large applications, but here is a
Reader example that is minimal for the points that I want to make:

module Main (main) where

-- https://hackage.haskell.org/package/base
import Control.Monad.IO.Class (MonadIO(liftIO))
import Data.Bool (bool)
import System.Environment (getArgs)

-- https://hackage.haskell.org/package/transformers
import Control.Monad.Trans.Reader (ReaderT(runReaderT), asks)

data Locale = En | It

class HasLocale a where
  getLocale :: a -> Locale

instance HasLocale Locale where
  getLocale = id

class MonadLocale m where
  askLocale :: m Locale

instance (HasLocale r, Monad m) => MonadLocale (ReaderT r m) where
  askLocale = asks getLocale

putLanguage :: (MonadIO m, MonadLocale m) => m ()
putLanguage = do
locale <- askLocale
liftIO . putStrLn $ case locale of
  En -> "English"
  It -> "Italiano"

putHelloWorld :: (MonadIO m, MonadLocale m) => m ()
putHelloWorld = do
locale  <- askLocale
liftIO . putStrLn $ case locale of
  En -> "Hello world!"
  It -> "Ciao mondo!"

app :: (MonadIO m, MonadLocale m) => m ()
app = do
putLanguage
putHelloWorld

main :: IO ()
main = do
locale <- bool En It . elem "--it" <$> getArgs
runReaderT app locale

In this example, the state/context is 

Beginners Digest, Vol 169, Issue 6

2023-02-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Reproduce example in Crypto.JWT (Pietro Grandinetti)
   2. Re:  Reproduce example in Crypto.JWT (Francesco Ariis)
   3. Re:  Reproduce example in Crypto.JWT (Pietro Grandinetti)
   4. Re:  Reproduce example in Crypto.JWT (Francesco Ariis)


--

Message: 1
Date: Sun, 26 Feb 2023 09:26:23 +
From: Pietro Grandinetti 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Reproduce example in Crypto.JWT
Message-ID:



Content-Type: text/plain; charset="iso-8859-1"

I am try to reproduce the first example here: 
https://hackage.haskell.org/package/jose-0.10/docs/Crypto-JWT.html
I can't seem to succeed with importing the function `runJOSE`

ghci> import Crypto.JWT
ghci> :t runJOSE

:1:1: error: Variable not in scope: runJOSE
ghci> import Crypto.JOSE.Error 
--https://github.com/frasertweedale/hs-jose/blob/master/src/Crypto/JOSE/Error.hs
ghci> :t runJOSE

:1:1: error: Variable not in scope: runJOSE

Can you point out what I am missing? Thanks.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 26 Feb 2023 11:55:39 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Reproduce example in Crypto.JWT
Message-ID: 
Content-Type: text/plain; charset=utf-8

Ciao Pietro,

Il 26 febbraio 2023 alle 09:26 Pietro Grandinetti ha scritto:
> I am try to reproduce the first example here: 
> https://hackage.haskell.org/package/jose-0.10/docs/Crypto-JWT.html
> I can't seem to succeed with importing the function `runJOSE`
> 
> ghci> import Crypto.JWT
> ghci> :t runJOSE

I `cabal get` jose-0.10, `cabal repl` and then

λ> import Crypto.JWT
λ> :t runJOSE
runJOSE :: JOSE e m a -> m (Either e a)

I would check if you the latest jose, and what :browse Crypto.JWT says
—F



--

Message: 3
Date: Sun, 26 Feb 2023 11:57:08 +
From: Pietro Grandinetti 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Reproduce example in Crypto.JWT
Message-ID:



Content-Type: text/plain; charset="cp1253"

Francesco,

Thanks.
I am using stack and the version doesn't match: `stack ls dependencies` shows 
`jose 0.9`. I can't seem to find a way to upgrade it even if I set `jose >= 
0.10` in the package.yaml file:

$ stack build
WARNING: Ignoring uhask's bounds on jose (>=0.10); using jose-0.9.
Reason: allow-newer enabled.
uhask> build (lib + exe)
Preprocessing library for uhask-0.1.0.0..
Building library for uhask-0.1.0.0..
[4 of 7] Compiling Modules.JWS
. <--- Errors about runJOSE not defined

$ stack install jose-0.10
No latest package revision found for: jose, dependency callstack: []

Google and SO didn't help so far. Can you suggest something to resolve this? 
Thanks.


From: Beginners  on behalf of Francesco Ariis 

Sent: Sunday, February 26, 2023 11:55 AM
To: beginners@haskell.org 
Subject: Re: [Haskell-beginners] Reproduce example in Crypto.JWT

Ciao Pietro,

Il 26 febbraio 2023 alle 09:26 Pietro Grandinetti ha scritto:
> I am try to reproduce the first example here: 
> https://hackage.haskell.org/package/jose-0.10/docs/Crypto-JWT.html
> I can't seem to succeed with importing the function `runJOSE`
>
> ghci> import Crypto.JWT
> ghci> :t runJOSE

I `cabal get` jose-0.10, `cabal repl` and then

λ> import Crypto.JWT
λ> :t runJOSE
runJOSE :: JOSE e m a -> m (Either e a)

I would check if you the latest jose, and what :browse Crypto.JWT says
—F

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 4
Date: Sun, 26 Feb 2023 13:05:41 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Reproduce example in Crypto.JWT
Message-ID: 
Content-Type: text/plain; charset=utf-8

Il 26 febbraio 2023 alle 11:57 Pietro Grandinetti ha scritto:
> Francesco,
> 
> Thanks.
> I am using stack and the version doesn't 

Beginners Digest, Vol 169, Issue 5

2023-02-23 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Understanding reason for Monad (Travis Cardwell)


--

Message: 1
Date: Thu, 23 Feb 2023 05:22:22 +0900
From: Travis Cardwell 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Understanding reason for Monad
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Hi Pietro,

The reply I wrote yesterday was sent when I ran out of time, but I have
since realized that I failed to get to the point.  Sorry about that!

The demo shows that you can use `hashPassword` with `IO` and
`ByteString`, as if the type was the following:

hashPassword :: Int -> ByteString -> IO ByteString

The use of type classes allows the function to be used with other types
as well, however.  This makes the function more flexible for different
people's needs.

For example, a project may use this function in a user registration
request handler.  Perhaps that request handler needs to write to a
database as well as perform logging.  It can be implemented using a
monad that has the context required for these features, so that the it
can do all of these things without being concerned with configuration
details.  The monad may have the following constraints:

* `MonadRandom m` so that `hashPassword` can be used
* `MonadLogger m` so that it can log in the configured way
* `MonadDatabase m` (using some application-defined monad) so that it
  has access to the application database

If `hashPassword` had the above `IO` type, then it would not work in
such an application monad directly.  If there is a `MonadIO` instance,
then one could use `liftIO`, but some application monads specifically
do *not* have `MonadIO` instances to make it more difficult to simply
run things in `IO`.

I am out of time again, but I hope this two-part reply is helpful.

Cheers,

Travis


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 169, Issue 5
*


Beginners Digest, Vol 169, Issue 4

2023-02-22 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Understanding reason for Monad (Pietro Grandinetti)
   2. Re:  Understanding reason for Monad (Kim-Ee Yeoh)
   3. Re:  Understanding reason for Monad (Travis Cardwell)


--

Message: 1
Date: Tue, 21 Feb 2023 13:17:14 +
From: Pietro Grandinetti 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Understanding reason for Monad
Message-ID:



Content-Type: text/plain; charset="iso-8859-1"

Hello--

I am going to use the function 'hashPassword' in [1] and I am not able to 
understand why the result is MonadRandom ByteArray instead of simply being a 
ByteString (or, ByteArray, or similar). Looking at [2], the only useful thing I 
can do with a MonadRandom a is to convert it to IO a. Why would a result of 
this determistic computation be a IO?

[1] - 
https://hackage.haskell.org/package/cryptonite-0.30/docs/Crypto-KDF-BCrypt.html
[2] - 
https://hackage.haskell.org/package/cryptonite-0.30/docs/Crypto-Random-Types.html#t:MonadRandom
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 21 Feb 2023 20:52:14 +0700
From: Kim-Ee Yeoh 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Understanding reason for Monad
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hi Pietro,

The hash algorithm you linked to is not a pure hash function.

Using pure hash functions for passwords make the resulting hashes
vulnerable to dictionary attacks.

The bcrypt algorithm incorporates random data—hence the use of
MonadRandom—called a salt, to generate a password hash resistant to
dictionary attacks.

(You’d probably get better answers to such questions on the cafe mailing
list. You seem to be well beyond the LYAH level, more power to you!)

Best, Kim-Ee

On Tue, Feb 21, 2023 at 8:17 PM Pietro Grandinetti 
wrote:

> Hello--
>
> I am going to use the function 'hashPassword' in [1] and I am not able to
> understand why the result is MonadRandom ByteArray instead of simply
> being a ByteString (or, ByteArray, or similar). Looking at [2], the only
> useful thing I can do with a MonadRandom a is to convert it to IO a. Why
> would a result of this determistic computation be a IO?
>
> [1] -
> https://hackage.haskell.org/package/cryptonite-0.30/docs/Crypto-KDF-BCrypt.html
> [2] -
> https://hackage.haskell.org/package/cryptonite-0.30/docs/Crypto-Random-Types.html#t:MonadRandom
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
-- Kim-Ee
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Wed, 22 Feb 2023 16:15:27 +0900
From: Travis Cardwell 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Understanding reason for Monad
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Hi Pietro,

Haskell type classes provide ad-hoc polymorphism.  Essentially, they
allow you to write a function that works with more than one concrete
type.



Function `hashPassword` has the following type:

hashPassword
  :: (MonadRandom m, ByteArray password, ByteArray hash)
  => Int
  -> password
  -> m hash

It has three constraints (listed before the double arrow):

Constraint `MonadRandom m` means that the function works in any monad
that has a `MonadRandom` instance and can therefore be used to generate
random values.  If you click `MonadRandom` in the documentation, you
can see which instances are built in.  There is an `IO` instance, so you
can run `hashPassword` in the `IO` monad.

Constraint `ByteArray password` means that the function accepts a
password of any type that has a `ByteArray` instance.  If you click
`ByteArray` in the documentation, you can see which instances are built
in.  There is a `ByteString` instance, so `hashPassword` can handle
`ByteString` password arguments.

Constraint `ByteArray 

Beginners Digest, Vol 169, Issue 3

2023-02-21 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Attoparsec.ByteString.Char8 or Attoparsec.ByteString for
  diff output? (Pedro B.)
   2. Re:  Attoparsec.ByteString.Char8 or Attoparsec.ByteString for
  diff output? (Kim-Ee Yeoh)


--

Message: 1
Date: Mon, 20 Feb 2023 10:39:06 -0400
From: "Pedro B." 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Attoparsec.ByteString.Char8 or
Attoparsec.ByteString for diff output?
Message-ID: <5bbd9ac4-f9b7-e443-405d-f5e47b734...@gmail.com>
Content-Type: text/plain; charset=UTF-8; format=flowed

I send this question to the haskell-cafe list and I've got a couple of 
answers there.

Pedro Borges


El 17/2/2023 a las 12:04 p. m., Pedro B. escribió:
> Dear Listers,
> 
> I am developing a program to parse dif output taken from stdin (as in 
> diff file1 file2 | myApp) or from a file. I am reading  the input as 
> ByteString in either case and I am parsing it Attoparsec. My question 
> is, Should I use Data.Attoparsec.ByteString.Char8  or 
> Data.Attoparsec.ByteString?
> 
> So far, I've been  using Data.Attoparsec.ByteString.Char8  and it works 
> for my sample files, which are in utf8 or, latin1, or the default 
> Windows encoding.
> 
> What do you suggest?
> 
> Regards,
> 
> Pedro Borges



--

Message: 2
Date: Tue, 21 Feb 2023 03:04:45 +0700
From: Kim-Ee Yeoh 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Attoparsec.ByteString.Char8 or
Attoparsec.ByteString for diff output?
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hi Pedro, I noticed the responses on the cafe list. Hope they helped!

On Mon, Feb 20, 2023 at 9:39 PM Pedro B.  wrote:

> I send this question to the haskell-cafe list and I've got a couple of
> answers there.
>
> Pedro Borges
>
>
> El 17/2/2023 a las 12:04 p. m., Pedro B. escribió:
> > Dear Listers,
> >
> > I am developing a program to parse dif output taken from stdin (as in
> > diff file1 file2 | myApp) or from a file. I am reading  the input as
> > ByteString in either case and I am parsing it Attoparsec. My question
> > is, Should I use Data.Attoparsec.ByteString.Char8  or
> > Data.Attoparsec.ByteString?
> >
> > So far, I've been  using Data.Attoparsec.ByteString.Char8  and it works
> > for my sample files, which are in utf8 or, latin1, or the default
> > Windows encoding.
> >
> > What do you suggest?
> >
> > Regards,
> >
> > Pedro Borges
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
-- Kim-Ee
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 169, Issue 3
*


Beginners Digest, Vol 169, Issue 2

2023-02-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Attoparsec.ByteString.Char8 or   Attoparsec.ByteString for
  diff output? (Pedro B.)


--

Message: 1
Date: Fri, 17 Feb 2023 12:04:28 -0400
From: "Pedro B." 
To: beginners@haskell.org
Subject: [Haskell-beginners] Attoparsec.ByteString.Char8 or
Attoparsec.ByteString for diff output?
Message-ID: <2dfc932c-969f-2dd7-c8b7-26ffcba1e...@gmail.com>
Content-Type: text/plain; charset=UTF-8; format=flowed

Dear Listers,

I am developing a program to parse dif output taken from stdin (as in 
diff file1 file2 | myApp) or from a file. I am reading  the input as 
ByteString in either case and I am parsing it Attoparsec. My question 
is, Should I use Data.Attoparsec.ByteString.Char8  or 
Data.Attoparsec.ByteString?

So far, I've been  using Data.Attoparsec.ByteString.Char8  and it works 
for my sample files, which are in utf8 or, latin1, or the default 
Windows encoding.

What do you suggest?

Regards,

Pedro Borges


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 169, Issue 2
*


Beginners Digest, Vol 169, Issue 1

2023-02-10 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Generic use of queries postgresql-simple (Pietro Grandinetti)


--

Message: 1
Date: Thu, 9 Feb 2023 14:08:05 +
From: Pietro Grandinetti 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Generic use of queries postgresql-simple
Message-ID:



Content-Type: text/plain; charset="iso-8859-1"

Hello--

I use postgresql-simple and for selecting rows from one table I have the 
following function.

runMyQuery :: Connection
   -> String   -- query with '?' params to bind
   -> Int  -- first param
   -> Int  -- second param
   -> IO [MyTable1]
runMyQuery conn dbQuery param1 param2 = query conn dbQuery $ (param2, param2)

data MyTable1 = MyTable1 {col1 :: Int, col2 :: Int, col3 :: String}

instance FromRow MyTable1 where fromRow = MyTable1 <$> field <*> field <*> 
field <*> field

There are some things I'd like to improve:

  1.  I will have to write "MyTable1", "MyTable2", ... datatypes, one for each 
table, but would like to have only one function runMyQuery where the return 
type is a generic IO [MyModel]. My problem is that I don't know how to write it 
for tables with different number of columns and different SQL types.
  2.  The 2nd to the penultimate arguments of runMyQuery are the arguments to 
bind into the SQL string query. This means that I should write several 
different version of "runMyQuery" each with a different number of arguments, 
but would like to have only one.

Can you recommend some approaches?

Thanks.

-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 169, Issue 1
*


Beginners Digest, Vol 168, Issue 1

2023-01-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  ways to use local ghc without installing packages via cabal
  install --lib (Dennis Raddle)


--

Message: 1
Date: Tue, 17 Jan 2023 14:07:48 -0800
From: Dennis Raddle 
To: Haskell Beginners 
Subject: [Haskell-beginners] ways to use local ghc without installing
packages via cabal install --lib
Message-ID:

Content-Type: text/plain; charset="utf-8"

I have a situation where I build some projects with stack (using VS Code
and HLS) and build some projects with ghc installed via ghcup. For the
latter I need to install the needed packages with cabal install --lib
 which are some of the same packages specified in my stack.yaml.

I've been playing with Windows, macOS, various versions of the resolver,
various versions of GHC, cabal, and stack. At one point I had both the HLS
and my local ghc builds working.

Recently I'm not sure what changed but I found myself needing to run cabal
install --lib on many packages. At that point HLS stopped working with the
message that it could not determine the local GHC version.

After poking around the web, it seems that similar problems were happening
for other people when they were running both a stack project and compiling
via ghc separately, and that cabal install --lib was a problem.

So I'm wondering if there's an alternative way of using separate ghc
builds.

Alternatively I can try to move everything under stack, that is doable, but
not as convenient for some things
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 168, Issue 1
*


Beginners Digest, Vol 167, Issue 1

2022-12-01 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Question on fromIntegral (Jonathan Drews)
   2. Re:  Question on fromIntegral (David McBride)
   3. Re:  Question on fromIntegral (Jonathan Drews)


--

Message: 1
Date: Wed, 30 Nov 2022 17:41:03 -0700
From: Jonathan Drews 
To: beginners@haskell.org
Subject: [Haskell-beginners] Question on fromIntegral
Message-ID: 
Content-Type: text/plain; charset=us-ascii

Hi Folks:

 I am using Glasgow Haskell Compilation System, version 9.2.4 on
OpenBSD 7.2. I am stumped by the following problem. If I run the
following program in ghci, then it works fine. Look:

fact :: Integer -> Integer
fact n = product [1..n]


term :: Double -> Double
term x  = x**4/fromIntegral(fact(4))

$ ghci
GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help
ghci> :l seriesTermTest.hs 
[1 of 1] Compiling Main ( seriesTermTest.hs, interpreted )
Ok, one module loaded.
ghci> term 1.0
4.1664e-2

However if I use fromIntegral inside a list comprehension like so:

fact :: Integer -> Integer
fact n = product [1..n]


expon :: Double -> Double
expon x  = sum [x**i/fromIntegral(fact(i)) | i <- [0..50]]

then I get the following error message:

$ ghci 
GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help
ghci> :l ePowerSeries.hs 
[1 of 1] Compiling Main ( ePowerSeries.hs, interpreted )

ePowerSeries.hs:6:40: error:
* Couldn't match expected type `Integer' with actual type `Double'
* In the first argument of `fact', namely `(i)'
  In the first argument of `fromIntegral', namely `(fact (i))'
  In the second argument of `(/)', namely `fromIntegral (fact
(i))'
  |
6 | expon x  = sum [x**i/fromIntegral(fact(i)) | i <- [0..50]]
  |^
Failed, no modules loaded.

What am I doing wrong?

--
Kind regards,
Jonathan



--

Message: 2
Date: Wed, 30 Nov 2022 23:05:21 -0500
From: David McBride 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Question on fromIntegral
Message-ID:

Content-Type: text/plain; charset="utf-8"

It is because (**) takes floating point numbers. In your first equation
both 4s are different. The second 4 is an Integer but the first is a some
Floating type aka 4.0.

In your second equation, both of those numbers are constrained to whatever
type i is, and fact demands an Integer and (**) demands a Float or Double
or some other Floating type, which cannot be reconciled.

You should be able to fix this with (untested)  x**fromIntegral(i), which
converts i from an Integer to Num and all Floating are Nums.

On Wed, Nov 30, 2022, 19:41 Jonathan Drews  wrote:

> Hi Folks:
>
>  I am using Glasgow Haskell Compilation System, version 9.2.4 on
> OpenBSD 7.2. I am stumped by the following problem. If I run the
> following program in ghci, then it works fine. Look:
>
> fact :: Integer -> Integer
> fact n = product [1..n]
>
>
> term :: Double -> Double
> term x  = x**4/fromIntegral(fact(4))
>
> $ ghci
> GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help
> ghci> :l seriesTermTest.hs
> [1 of 1] Compiling Main ( seriesTermTest.hs, interpreted )
> Ok, one module loaded.
> ghci> term 1.0
> 4.1664e-2
>
> However if I use fromIntegral inside a list comprehension like so:
>
> fact :: Integer -> Integer
> fact n = product [1..n]
>
>
> expon :: Double -> Double
> expon x  = sum [x**i/fromIntegral(fact(i)) | i <- [0..50]]
>
> then I get the following error message:
>
> $ ghci
> GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help
> ghci> :l ePowerSeries.hs
> [1 of 1] Compiling Main ( ePowerSeries.hs, interpreted )
>
> ePowerSeries.hs:6:40: error:
> * Couldn't match expected type `Integer' with actual type `Double'
> * In the first argument of `fact', namely `(i)'
>   In the first argument of `fromIntegral', namely `(fact (i))'
>   In the second argument of `(/)', namely `fromIntegral (fact
> (i))'
>   |
> 6 | expon x  = sum [x**i/fromIntegral(fact(i)) | i <- [0..50]]
>   |^
> Failed, no modules loaded.
>
> What am I doing wrong?
>
> --
> Kind regards,
> Jonathan
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> 

Beginners Digest, Vol 166, Issue 2

2022-11-14 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  How to create a monad in GHC 7.10 or newer (Ahmad Ismail)
   2. Re:  How to create a monad in GHC 7.10 or newer (Francesco Ariis)
   3. Re:  How to create a monad in GHC 7.10 or newer (Ahmad Ismail)


--

Message: 1
Date: Sun, 13 Nov 2022 20:56:32 +0600
From: Ahmad Ismail 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] How to create a monad in GHC 7.10 or
newer
Message-ID:

Content-Type: text/plain; charset="utf-8"

How can I fix it so that `ItDoesnt <*> WhatThisIsCalled` works?

I have came up with a solution without WhatThisIsCalled

data WhoCares a = ItDoesnt | Matter a deriving (Eq, Show)

instance Functor WhoCares where
fmap _ ItDoesnt = ItDoesnt
fmap f (Matter a) = Matter (f a)

instance Applicative WhoCares where
pure = Matter
Matter f <*> Matter a = Matter (f a)
ItDoesnt <*> _ = ItDoesnt
_ <*> ItDoesnt = ItDoesnt

instance Monad WhoCares where
return x = Matter x
(Matter x) >>= k = k x
ItDoesnt >>= _ = ItDoesnt

half x = if even x
then Matter (x `div` 2)
else ItDoesnt

incVal :: (Ord a, Num a) => a -> WhoCares a
incVal x
| x + 1 <= 10 = return (x + 1)
| otherwise = ItDoesnt

decVal :: (Ord a, Num a) => a -> WhoCares a
decVal x
| x - 1 >= 0 = return (x - 1)
| otherwise = ItDoesnt

main = do
-- fmap id == id
let funcx = fmap id "Hi Julie"
let funcy = id "Hi Julie"
print(funcx)
print(funcy)
print(funcx == funcy)

-- fmap (f . g) == fmap f . fmap g
let funcx' = fmap ((+1) . (*2)) [1..5]
let funcy' = fmap (+1) . fmap (*2) $ [1..5]
print(funcx')
print(funcy')
print(funcx' == funcy')

-- pure id <*> v = v
print(pure id <*> (Matter 10))

-- pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
let appx = pure (.) <*> (Matter (+1)) <*> (Matter (*2)) <*> (Matter 10)
let appy = (Matter (+1)) <*> ((Matter (*2)) <*> (Matter 10))
print(appx)
print(appy)
print(appx == appy)

-- pure f <*> pure x = pure (f x)
let appx' = pure (+1) <*> pure 1 :: WhoCares Int
let appy' = pure ((+1) 1) :: WhoCares Int
print(appx')
print(appy')
print(appx' == appy')

-- u <*> pure y = pure ($ y) <*> u
let appx'' = Matter (+2) <*> pure 2
let appy'' = pure ($ 2) <*> Matter (+ 2)
print(appx'')
print(appy'')
print(appx'' == appy'')

-- m >>= return = m
let monx = Matter 20 >>= return
let mony = Matter 20
print(monx)
print(mony)
print(monx == mony)

-- return x >>= f = f x
let monx' = return 20 >>= half
let mony' = half 20
print(monx')
print(mony')
print(monx' == mony')

-- (m >>= f) >>= g = m >>= (\x -> f x >>= g)
let monx'' = return 20 >>= half >>= half
let mony'' = half 20 >>= half
print(monx'')
print(mony'')
print(monx'' == mony'')

print (Matter 7 >>= incVal >>= incVal >>= incVal)
print (Matter 7 >>= incVal >>= incVal >>= incVal >>= incVal)
print (Matter 7 >>= incVal >>= incVal >>= incVal >>= incVal >>= decVal
>>= decVal)
print (Matter 2 >>= decVal >>= decVal >>= decVal)
print (Matter 20 >>= half >>= half)

*Thanks and Best Regards,Ahmad Ismail*


On Sun, Nov 13, 2022 at 5:08 PM Francesco Ariis  wrote:

> Hello Ahmad,
>
> Il 13 novembre 2022 alle 16:33 Ahmad Ismail ha scritto:
> > Due to lack of examples, I am not understanding how to implement >>= and
> > >>.
>
> All you need to implement is (>>=)!
>
> > The code I came up with so far is:
> >
> > instance Monad (WhoCares a) where
> > (>>=) :: Matter a -> (a -> Matter b) -> Matter b
> > (>>) :: Matter a -> Matter b -> Matter b
> > return :: a -> Matter a
> > return = pure
>
> The signature for (>>=) is wrong, `Matter` is a *data* constructor, you
> need a *type* one instead, so:
>
> (>>=) :: WhoCares a -> (a -> WhoCares b) -> WhoCares b
>
> But let us go back to typeclasses. Your `Applicative` instance
>
> > instance Applicative WhoCares where
> >   pure = Matter
> >   Matter f <*> Matter a = Matter (f a)
>
> is broken:
>
> λ> ItDoesnt <*> WhatThisIsCalled
> *** Exception: /tmp/prova.hs:11:5-40: Non-exhaustive patterns in
> function <*>
>
> So we need first to fix that. What behaviour would you expect, what are
> you trying to model with `WhoCares`?
> —F
> 

Beginners Digest, Vol 166, Issue 1

2022-11-13 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  How to create a monad in GHC 7.10 or newer (Ahmad Ismail)
   2. Re:  How to create a monad in GHC 7.10 or newer (Francesco Ariis)


--

Message: 1
Date: Sun, 13 Nov 2022 16:33:54 +0600
From: Ahmad Ismail 
To: beginners@haskell.org
Subject: [Haskell-beginners] How to create a monad in GHC 7.10 or
newer
Message-ID:

Content-Type: text/plain; charset="utf-8"

In the book "Haskell programming from first principles" it is said that:

If you are using GHC 7.10 or newer, you’ll see an Applicative constraint in
> the definition of Monad, as it should be:



class Applicative m => Monad m where
> (>>=) :: m a -> (a -> m b) -> m b
> (>>) :: m a -> m b -> m b
> return :: a -> m a


I have created the following applicative functor.

data WhoCares a = ItDoesnt | Matter a | WhatThisIsCalled deriving (Eq, Show)

instance Functor WhoCares where
fmap _ ItDoesnt = ItDoesnt
fmap _ WhatThisIsCalled = WhatThisIsCalled
fmap f (Matter a) = Matter (f a)

instance Applicative WhoCares where
pure = Matter
Matter f <*> Matter a = Matter (f a)

main = do

-- fmap id == id
let funcx = fmap id "Hi Julie"
let funcy = id "Hi Julie"
print(funcx)
print(funcy)
print(funcx == funcy)

-- fmap (f . g) == fmap f . fmap g
let funcx' = fmap ((+1) . (*2)) [1..5]
let funcy' = fmap (+1) . fmap (*2) $ [1..5]
print(funcx')
print(funcy')
print(funcx' == funcy')

-- pure id <*> v = v
print(pure id <*> (Matter 10))

-- pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
let appx = pure (.) <*> (Matter (+1)) <*> (Matter (*2)) <*> (Matter 10)
let appy = (Matter (+1)) <*> ((Matter (*2)) <*> (Matter 10))
print(appx)
print(appy)
print(appx == appy)

-- pure f <*> pure x = pure (f x)
let appx' = pure (+1) <*> pure 1 :: WhoCares Int
let appy' = pure ((+1) 1) :: WhoCares Int
print(appx')
print(appy')
print(appx' == appy')

-- u <*> pure y = pure ($ y) <*> u
let appx'' = Matter (+2) <*> pure 2
let appy'' = pure ($ 2) <*> Matter (+ 2)
print(appx'')
print(appy'')
print(appx'' == appy'')

Due to lack of examples, I am not understanding how to implement >>= and
>>. The code I came up with so far is:

instance Monad (WhoCares a) where
(>>=) :: Matter a -> (a -> Matter b) -> Matter b
(>>) :: Matter a -> Matter b -> Matter b
return :: a -> Matter a
return = pure

So, that I can do stuff like:

half x = if even x
then Matter (x `div` 2)
else ItDoesnt

incVal :: (Ord a, Num a) => a -> WhoCares a
incVal x
| x + 1 <= 10 = return (x + 1)
| otherwise = ItDoesnt

decVal :: (Ord a, Num a) => a -> WhoCares a
decVal x
| x - 1 >= 0 = return (x - 1)
| otherwise = ItDoesnt

main = do
print (Matter 7 >>= incVal >>= incVal >>= incVal)
print (Matter 7 >>= incVal >>= incVal >>= incVal >>= incVal)
print (Matter 7 >>= incVal >>= incVal >>= incVal >>= incVal >>= decVal
>>= decVal)
print (Matter 2 >>= decVal >>= decVal >>= decVal)
print(Matter 20 >>= half >>= half)

With Output:

10
ItDoesnt
ItDoesnt
ItDoesnt
5

Please help.

*Thanks and Best Regards,Ahmad Ismail*
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 13 Nov 2022 12:07:38 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to create a monad in GHC 7.10 or
newer
Message-ID: 
Content-Type: text/plain; charset=utf-8

Hello Ahmad,

Il 13 novembre 2022 alle 16:33 Ahmad Ismail ha scritto:
> Due to lack of examples, I am not understanding how to implement >>= and
> >>.

All you need to implement is (>>=)!

> The code I came up with so far is:
> 
> instance Monad (WhoCares a) where
> (>>=) :: Matter a -> (a -> Matter b) -> Matter b
> (>>) :: Matter a -> Matter b -> Matter b
> return :: a -> Matter a
> return = pure

The signature for (>>=) is wrong, `Matter` is a *data* constructor, you
need a *type* one instead, so:

(>>=) :: WhoCares a -> (a -> WhoCares b) -> WhoCares b

But let us go back to typeclasses. Your `Applicative` instance

> instance Applicative WhoCares where
>   pure = Matter
>   Matter f <*> Matter a = Matter (f a)

is broken:

λ> ItDoesnt 

Beginners Digest, Vol 165, Issue 2

2022-06-17 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Invoking ghci with hackage modules (יהושע ולך)
   2. Re:  Invoking ghci with hackage modules (Simon Jakobi)


--

Message: 1
Date: Thu, 16 Jun 2022 15:21:09 +0300
From: יהושע ולך 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Invoking ghci with hackage modules
Message-ID:

Content-Type: text/plain; charset="utf-8"

if you're using stack, then indeed, as Sylvain said.
if not, this means that the ghci that is being used, and it's relevant
haskell does not have "random" installed. so for example if this is the
system installed one, install the relevant package with haskell's random
too.

On Thu, Jun 16, 2022 at 9:55 AM Sylvain Henry  wrote:

> Hi,
>
> With Stack:
>
>  > stack ghci --resolver=lts-18.28 --package=random arrows.hs
>
> You can use Stack's script feature to specify resolver and packages
> directly in the .hs file. See
> https://www.wespiser.com/posts/2020-02-02-Command-Line-Haskell.html for
> some examples.
>
> Cheers,
> Sylvain
>
>
> On 16/06/2022 01:39, Lists0 wrote:
> > Hi all,
> >
> > a very basic question, that I cannot solve alone:
> > How do I load modules from hackage into ghci ?
> > Say, I have a module arrows.hs :
> >
> > {-# LANGUAGE Arrows #-}
> >
> > module Main where
> > import Control.Arrow
> > import Control.Monad
> > import qualified Control.Category as Cat
> > import Data.List
> > import Data.Maybe
> > import System.Random
> >
> >
> > I get the error in ghci:
> >
> > % ghci arrows.hs
> > GHCi, version 8.10.6: https://www.haskell.org/ghc/  :? for help
> > [1 of 1] Compiling Main ( arrows.hs, interpreted )
> >
> > arrows.hs:9:1: error:
> >  Could not find module ‘System.Random’
> >  Use -v (or `:set -v` in ghci) to see a list of the files searched
> > for. |
> > 9 | import System.Random
> >| 
> > Failed, no modules loaded.
> > Prelude>
> >
> >
> > System.Random is in the package "random" from hackage, where the other
> > modules are in the package base.
> >
> > I cannot find a solution in the doku that works :-(
> >
> > Thanks for help!
> >
> > ___
> > Beginners mailing list
> > Beginners@haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


--
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Thu, 16 Jun 2022 17:17:50 +0200
From: Simon Jakobi 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Invoking ghci with hackage modules
Message-ID:

Content-Type: text/plain; charset="UTF-8"

With cabal repl, you can specify dependencies on Hackage with
--build-depends or -b for short, e.g.

cabal repl --build-depends random

Am Do., 16. Juni 2022 um 05:19 Uhr schrieb Lists0 :
>
>
> Hi all,
>
> a very basic question, that I cannot solve alone:
> How do I load modules from hackage into ghci ?
> Say, I have a module arrows.hs :
>
> {-# LANGUAGE Arrows #-}
>
> module Main where
> import Control.Arrow
> import Control.Monad
> import qualified Control.Category as Cat
> import Data.List
> import Data.Maybe
> import System.Random
>
>
> I get the error in ghci:
>
> % ghci arrows.hs
> GHCi, version 8.10.6: https://www.haskell.org/ghc/  :? for help
> [1 of 1] Compiling Main ( arrows.hs, interpreted )
>
> arrows.hs:9:1: error:
> Could not find module ‘System.Random’
> Use -v (or `:set -v` in ghci) to see a list of the files searched
> for. |
> 9 | import System.Random
>   | 
> Failed, no modules loaded.
> Prelude>
>
>
> System.Random is in the package "random" from hackage, where the other
> modules are in the package base.
>
> I cannot find a solution in the doku that works :-(
>
> Thanks for help!
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

Subject: Digest Footer


Beginners Digest, Vol 165, Issue 1

2022-06-16 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Invoking ghci with hackage modules (Lists0)
   2. Re:  Invoking ghci with hackage modules (Sylvain Henry)


--

Message: 1
Date: Thu, 16 Jun 2022 01:39:03 +0200
From: Lists0 
To: beginners@haskell.org
Subject: [Haskell-beginners] Invoking ghci with hackage modules
Message-ID: <20220616012615.3072c94c@duin>
Content-Type: text/plain; charset=UTF-8


Hi all,

a very basic question, that I cannot solve alone:
How do I load modules from hackage into ghci ?
Say, I have a module arrows.hs : 

{-# LANGUAGE Arrows #-}

module Main where
import Control.Arrow
import Control.Monad
import qualified Control.Category as Cat
import Data.List
import Data.Maybe
import System.Random


I get the error in ghci:

% ghci arrows.hs
GHCi, version 8.10.6: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main ( arrows.hs, interpreted )

arrows.hs:9:1: error:
Could not find module ‘System.Random’
Use -v (or `:set -v` in ghci) to see a list of the files searched
for. |
9 | import System.Random
  | 
Failed, no modules loaded.
Prelude> 


System.Random is in the package "random" from hackage, where the other
modules are in the package base.

I cannot find a solution in the doku that works :-(

Thanks for help!



--

Message: 2
Date: Thu, 16 Jun 2022 08:52:03 +0200
From: Sylvain Henry 
To: 
Subject: Re: [Haskell-beginners] Invoking ghci with hackage modules
Message-ID: <9f110887-8ec7-8d21-30b7-e25bf262e...@haskus.fr>
Content-Type: text/plain; charset="UTF-8"; format=flowed

Hi,

With Stack:

 > stack ghci --resolver=lts-18.28 --package=random arrows.hs

You can use Stack's script feature to specify resolver and packages 
directly in the .hs file. See 
https://www.wespiser.com/posts/2020-02-02-Command-Line-Haskell.html for 
some examples.

Cheers,
Sylvain


On 16/06/2022 01:39, Lists0 wrote:
> Hi all,
>
> a very basic question, that I cannot solve alone:
> How do I load modules from hackage into ghci ?
> Say, I have a module arrows.hs :
>
> {-# LANGUAGE Arrows #-}
>
> module Main where
> import Control.Arrow
> import Control.Monad
> import qualified Control.Category as Cat
> import Data.List
> import Data.Maybe
> import System.Random
>
>
> I get the error in ghci:
>
> % ghci arrows.hs
> GHCi, version 8.10.6: https://www.haskell.org/ghc/  :? for help
> [1 of 1] Compiling Main ( arrows.hs, interpreted )
>
> arrows.hs:9:1: error:
>  Could not find module ‘System.Random’
>  Use -v (or `:set -v` in ghci) to see a list of the files searched
> for. |
> 9 | import System.Random
>| 
> Failed, no modules loaded.
> Prelude>
>
>
> System.Random is in the package "random" from hackage, where the other
> modules are in the package base.
>
> I cannot find a solution in the doku that works :-(
>
> Thanks for help!
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 165, Issue 1
*


Beginners Digest, Vol 164, Issue 1

2022-04-08 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Utrecht Summer School on Advanced Functional Programming
  2022 (Swierstra, W.S. (Wouter))


--

Message: 1
Date: Fri, 8 Apr 2022 09:45:04 +
From: "Swierstra, W.S. (Wouter)" 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Utrecht Summer School on Advanced
Functional  Programming 2022
Message-ID: <3dedd1a7-d19d-744d-1163-356c134fd...@uu.nl>
Content-Type: text/plain; charset="utf-8"


# Call for Participation

   SUMMER SCHOOL ON ADVANCED FUNCTIONAL PROGRAMMING

 Utrecht, the Netherlands, 04 July – 08 July 2022

   http://www.afp.school

## ABOUT

The Advanced Functional Programming summer school has been running for
more than ten years. We aim to educate aspiring Haskell programmers
beyond the basic material covered by many textbooks.

After running remotely for the past two years, we're thrilled to
announce that this year's edition will take place on site in
Utrecht. We are monitoring the pandemic closely - and will make
contingency plans if we cannot meet in person; at the moment, we do
not have plans for remote participation.

The lectures will cover several more advanced topics regarding the
theory and practice of Haskell programming, including topics such as:

   * lambda calculus;
   * monads and monad transformers;
   * lazy evaluation;
   * generalized algebraic data types;
   * type families and type-level programming;
   * concurrency and parallelism.

The summer school consists of a mix of lectures, labs, and a busy
social program.

## LECTURERS

* Gabriele Keller
* Trevor McDonell
* Wouter Swierstra

## PREREQUISITES

We expect students to have a basic familiarity with Haskell
already. You should be able to write recursive functions over
algebraic data types, such as lists and trees. There is a great deal
of material readily available that covers this material. If you've
already started learning Haskell and are looking to take your
functional programming skills to the next level, this is the course
for you.

## DATES

Soft registration deadline: 24 June, 2022
School: 04 July – 08 July 2022

## COSTS

   750 euro - Profession registration only
   250 euro - Student registration fee
   200 euro - Housing fee

We will charge a registration fee of 750 euros (or 250 euros for
students) to cover our expenses. If this is problematic for you for
any reason at all, please email the organisers and we can try to offer
you a discounted rate or a fee waiver. We have a limited number of
scholarships or discounts available for students that would not be
able to attend otherwise, especially for women and under-represented
minorities.

## FURTHER INFORMATION

Further information, including instructions on how to register, is
available on our website:

   http://www.afp.school

--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 164, Issue 1
*


Beginners Digest, Vol 163, Issue 1

2022-02-07 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Evaluation oddity (Torsten Otto)
   2. Re:  Evaluation oddity (Francesco Ariis)


--

Message: 1
Date: Sun, 6 Feb 2022 19:00:41 +0100
From: Torsten Otto 
To: beginners@haskell.org
Subject: [Haskell-beginners] Evaluation oddity
Message-ID: <7345cfa8-899b-4331-88a6-6d5e8f04f...@gmx.de>
Content-Type: text/plain;   charset=utf-8

Hi all,

maybe one of you sees a difference, I sure don’t… The full code for this is 
below.

When I call 

*Main> diffieH 23 16 20
13

and use the result in

*Main> encipher "abc" 13
„nop"

I get the letters to be expected. However, when I combine these into

> start text p a b = encipher text (diffieH p a b)

*Main> start "abc" 23 16 20
„efg"

the result changes. 

Any hints are most welcome. 

Thank you and regards
Torsten







> import Data.Char

> diffieH p a b = (b ^ a) `mod` p

> number2letter number = chr (number + 96)
> letter2number letter = (ord letter) - 96

> start text p a b = encipher text (diffieH p a b)

> encipher []   _  = []
> encipher (b:rest) key   = (number2letter (((letter2number b)+key) `mod` 26)) 
> : (encipher rest key)



--

Message: 2
Date: Sun, 6 Feb 2022 20:02:47 +0100
From: Francesco Ariis 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Evaluation oddity
Message-ID: 
Content-Type: text/plain; charset=utf-8

Hello Otto,

Il 06 febbraio 2022 alle 19:00 Torsten Otto ha scritto:
> When I call 
> 
> *Main> diffieH 23 16 20
> 13
> 
> and use the result in
> 
> *Main> encipher "abc" 13
> „nop"
> 
> I get the letters to be expected. However, when I combine these into
> 
> > start text p a b = encipher text (diffieH p a b)
> 
> *Main> start "abc" 23 16 20
> „efg"
> 
> the result changes. 

You should always write top level signatures by hand in your
code. What is the signature that you want for `diffieH`?
This is the inferred one

λ> :t diffieH
diffieH :: (Integral a, Integral b) => a -> b -> a -> a


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 163, Issue 1
*


Beginners Digest, Vol 162, Issue 2

2022-01-28 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Parsing a file (Roger Mason)
   2. Re:  Parsing a file (Roger Mason)


--

Message: 1
Date: Thu, 27 Jan 2022 08:51:01 -0330
From: Roger Mason 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Parsing a file
Message-ID: 
Content-Type: text/plain

Hello Francesco,

Thanks for your help.

Francesco Ariis  writes:

>
> Simple quiz: do you understand why
>
> main :: IO ()
> main = "prova"
>

That returns a String rather than an "IO something".

> does nor work (nor compile) while
>
> main :: IO ()
> main = putStrLn "prova"
>
> does?

putStrLn returns an "IO something" and so is campatible with the type of
main.

Thank you for the help & encouragement.

Roger


--

Message: 2
Date: Thu, 27 Jan 2022 08:55:02 -0330
From: Roger Mason 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Parsing a file
Message-ID: 
Content-Type: text/plain

Hello David,

David McBride  writes:

> These two pieces of code are not equivalent.
>
>   :{
>  input = do
>eqatoms <- readFile "Parsing_File/eqatoms.out"
>return eqatoms
>:}
>
>:{
>  main = do
>eqatoms <- readFile "Parsing_File/eqatoms.out"
>Parsec.parse species "test species" eqatoms
>  return
>:}

Thank you for the help.  Now I understand better the error that I made.

Roger


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 162, Issue 2
*


Beginners Digest, Vol 162, Issue 1

2022-01-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Parsing a file (Roger Mason)
   2. Re:  Parsing a file (Francesco Ariis)
   3. Re:  Parsing a file (Roger Mason)
   4. Re:  Parsing a file (Francesco Ariis)
   5. Re:  Parsing a file (David McBride)


--

Message: 1
Date: Wed, 26 Jan 2022 08:40:10 -0330
From: Roger Mason 
To: 
Subject: [Haskell-beginners] Parsing a file
Message-ID: 
Content-Type: text/plain

Hello,

Warning: long post.

I've worked my way through various parsing tutorials using either Parsec
or ReadP.  I reached a point where I need to try parsing one of the
types of file for which I'm writing the parser.  I have written parsers
for various parts of this file:

eqatoms.out:
==

Species :1 (Si)
 atom1 is equivalent to atom(s)
   1   2   3
 atom2 is equivalent to atom(s)
   1   2   3
 atom3 is equivalent to atom(s)
   1   2   3

Species :2 (O)
 atom1 is equivalent to atom(s)
   1   2   3   4   5   6
 atom2 is equivalent to atom(s)
   1   2   3   4   5   6
 atom3 is equivalent to atom(s)
   1   2   3   4   5   6
 atom4 is equivalent to atom(s)
   1   2   3   4   5   6
 atom5 is equivalent to atom(s)
   1   2   3   4   5   6
 atom6 is equivalent to atom(s)
   1   2   3   4   5   6

==

These are my imports:
==
  import qualified Text.Parsec as Parsec

  import Text.Parsec (())

  import Control.Applicative

  import Control.Monad.Identity (Identity)
==

These are my parsers:
==
   :{
species :: Parsec.Parsec String () (String,String)
species = do
 --Parsec.char 'S'
 Parsec.string "Species"
 Parsec.spaces
 Parsec.char ':'
 Parsec.spaces
 digits <- Parsec.many1 Parsec.digit
 Parsec.spaces
 Parsec.char '('
 id <- Parsec.many1 Parsec.letter
 return (id,digits)
   :}

   :{
atom = do
 Parsec.spaces
 Parsec.string "atom"
 Parsec.spaces
 digits <- Parsec.digit
 return digits
   :}

:{
  equivalents = do
   Parsec.spaces
   digits <- Parsec.digit
   return digits
:}
==

Some simple tests:
==
src = "oops"
Parsec.parse species src "Species :1 (Si)"

Right ("Si","1")

src = "Parsing_File/eqatoms.out"
Parsec.parse atom src "atom5 is equivalent to atom(s)"

Right '5'

src = "Parsing_File/eqatoms.out"
Parsec.parse (Parsec.many1 equivalents) src "   1   2   3   4   5   6"

: Right "123456"
==

So, the individual parsers work as intended.  However, parsing an actual
file does not work.

I define a function to return the file contents:
==
   :{
 input = do
   eqatoms <- readFile "Parsing_File/eqatoms.out"
   return eqatoms
   :}
==

A test shows that my reader works:
==
input

: Species :1 (Si)\n atom1 is equivalent to atom(s)\n   1   2
3\n atom2 is equivalent to atom(s)\n   1   2   3\n atom3 is
equivalent to atom(s)\n   1   2   3\n\nSpecies :2 (O)\n atom1 is
equivalent to atom(s)\n   1   2   3   4   5   6\n atom2 is
equivalent to atom(s)\n   1   2   3   4   5   6\n atom3 is
equivalent to atom(s)\n   1   2   3   4   5   6\n atom4 is
equivalent to atom(s)\n   1   2   3   4   5   6\n atom5 is
equivalent to atom(s)\n   1   2   3   4   5   6\n atom6 is
equivalent to atom(s)\n   1   2   3   4   5   6\n

==

I attempt to parse the input:
==
   :{
 main = do
 eqatoms <- readFile "Parsing_File/eqatoms.out"
 Parsec.parse species "test species" eqatoms
 return
   :}

Prelude Parsec Text.Parsec Control.Applicative Control.Monad.Identity| Prelude 
Parsec Text.Parsec Control.Applicative Control.Monad.Identity| Prelude Parsec 
Text.Parsec Control.Applicative Control.Monad.Identity| Prelude Parsec 
Text.Parsec Control.Applicative Control.Monad.Identity| Prelude Parsec 
Text.Parsec Control.Applicative Control.Monad.Identity| 
:250:3: error:

Beginners Digest, Vol 161, Issue 5

2021-12-31 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Coercing existential according to type-level Maybe
  (Dmitriy Matrosov)
   2. Re:  Coercing existential according totype-level Maybe
  (Kim-Ee Yeoh)


--

Message: 1
Date: Thu, 30 Dec 2021 16:10:01 +0300
From: Dmitriy Matrosov 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Coercing existential according to
type-level  Maybe
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Hi.

I've tried to write a function to coerce existential value according to type
stored in type-level 'Maybe' (i.e. 'Just or 'Nothing).

> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE RankNTypes #-}
> {-# LANGUAGE KindSignatures #-}
> {-# LANGUAGE PolyKinds #-}
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE GADTs #-}
>
> import Data.Kind
> import Data.Proxy
> import Unsafe.Coerce
>
> class FromTypeMaybe k where
> type ToType k
> fromTypeMaybe :: (a -> ToType k) -> Proxy k -> a -> Maybe (ToType k)
>
> instance forall (t :: Type). FromTypeMaybe ('Nothing :: Maybe t) where
> type ToType 'Nothing = t
> fromTypeMaybe f _ x = Nothing
>
> instance forall (t :: Type). FromTypeMaybe ('Just t :: Maybe Type) where
> type ToType ('Just t) = t
> fromTypeMaybe f _ x = Just (f x)
>
> data Any where
> Any :: a -> Any
>
> unAny :: Any -> t
> unAny (Any x) = unsafeCoerce x

This works as far as i can see

*Main> fromTypeMaybe unAny (Proxy @('Just Int)) (Any 3)
Just 3
*Main> fromTypeMaybe unAny (Proxy @'Nothing) undefined
Nothing

but i don't understand how 'Nothing instance works:

   type   kind  kind?
vvv  vv  vvv
instance forall (t :: Type). FromTypeMaybe ('Nothing :: Maybe t) where
 type ToType 'Nothing = t
   ^^^
   type

(in case alignment breaks: variable 't' in forall is type-variable with kind
'Type', but in "Maybe t" in instance head it's used as kind-variable. And then
in associated type-family the same variable 't' is used as type-variable
again).

If i try to write "'Nothing"'s kind as 'Maybe Type' (in the same manner as
'Just has)

instance forall (t :: Type). FromTypeMaybe ('Nothing :: Maybe Type) where

i get an error:

1.lhs:21:3: error:
• Type variable ‘t’ is mentioned in the RHS,
but not bound on the LHS of the family instance
• In the type instance declaration for ‘ToType’
  In the instance declaration for
‘FromTypeMaybe ('Nothing :: Maybe Type)’
   |
21 | > instance forall (t :: Type). FromTypeMaybe ('Nothing ::
Maybe Type) where
   |   
^...

Well, i'm not sure, that understand why 'forall' in instance head may not be
used as family's LHS, but.. that's probably ok.  On the other hand, if i try
to write 'Just instance using type-variable 't' as kind-variable (in the same
manner as 'Nothing has):

instance forall (t :: Type). FromTypeMaybe ('Just t :: Maybe t) where

i get an error too:

1.lhs:25:47: error:
• Expected kind ‘Maybe t’, but ‘'Just t’ has kind ‘Maybe *’
• In the first argument of ‘FromTypeMaybe’, namely
‘('Just t :: Maybe t)’
  In the instance declaration for
‘FromTypeMaybe ('Just t :: Maybe t)’
   |
25 | > instance forall (t :: Type). FromTypeMaybe ('Just t :: Maybe t) where

Well, that's also probably expected, because though i've declared
type-variable 't' with kind 'Type' in forall, due to 'DataKinds' extension
type 't' is also promoted to kind 't' and, thus, by using ('Just t :: Maybe t)
i say, that ('Just t) should have kind 'Maybe t', not 'Maybe Type', which it
really has.

But if that's so, how working 'Nothing instance

instance forall (t :: Type). FromTypeMaybe ('Nothing :: Maybe t) where

may work at all? It has the same problem as 'Just instance above:
type-variable 't' is promoted to kind 't' and 'Nothing will have kind 'Maybe
t' instead of 'Maybe Type' ?


--

Message: 2
Date: Thu, 30 Dec 2021 22:40:47 +0800
From: Kim-Ee Yeoh 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: 

Beginners Digest, Vol 161, Issue 4

2021-12-29 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Monad  question (c...@coot.me)


--

Message: 1
Date: Tue, 28 Dec 2021 18:34:53 +
From: c...@coot.me
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Monad  question
Message-ID:



Content-Type: text/plain; charset="utf-8"

Hi Mike,

An applicative instance of `Maybe` is enough to write the convert function 
you're looking for.  Applicative is very useful when there are no dependencies 
between different branches, like when converting `Add`.  But anyway, converting 
between applicative and monadic operations is a good exercise, which I'll leave 
for you.  It's always possible to convert from applicative to monadic form, but 
the more useful conversion is from monadic to applicative (which is not always 
possible):
 

```
convert :: Expr (Maybe a) -> Maybe (Expr a)
convert (Var a)   = Var <$> a
convert (Add a b) = Add <$> convert a
<*> convert b

```

Best regards,
Marcin

Sent with ProtonMail Secure Email.

‐‐‐ Original Message ‐‐‐

On Thursday, November 25th, 2021 at 18:10, mike h  
wrote:

> Hi,
> 

> This isn’t homework! I’ve been staring at this for several hours - and that 
> usually works.
> 

> I also tried typed holes to no avail. I thinks it is quite simple really but 
> I’ve gone past seeing it!
> 

> I have
> 

> data Expr a = Var a | Add (Expr a) (Expr a)
> 

> and would like to write
> 

> convert :: Expr (Maybe a) -> Maybe (Expr a)
> 

> which returns Nothing if there is an occurrence of Nothing inside the
> 

> input expression e, otherwise it returns Just e', where e'
> 

> is a new expression where the internal values of type a are not wrapped in 
> Just.
> 

> You should use the functionality of the Maybe monad to implement
> 

> the convert function.
> 

> Thanks
> 

> Mike
> 

> Beginners mailing list
> 

> Beginners@haskell.org
> 

> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 509 bytes
Desc: OpenPGP digital signature
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 161, Issue 4
*


Beginners Digest, Vol 161, Issue 3

2021-12-13 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Beginners Digest, Vol 161, Issue 1 (יהושע ולך)
   2. Re:  Non-exhaustive patterns (Jeffrey Brown)


--

Message: 1
Date: Sun, 12 Dec 2021 19:11:25 +0200
From: יהושע ולך 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 161, Issue 1
Message-ID:

Content-Type: text/plain; charset="utf-8"

http://learnyouahaskell.com/input-and-output

might help.


‪On Sun, Dec 12, 2021 at 7:09 PM ‫יהושע ולך‬‎  wrote:‬

> The important thing here, is that print is a function from a "pure" value
> (any type implements the Show typeclass. (similar to trait in rust, or
> interface in some languages))
> and creates a "IO" value, which can be thought of as a IO action. inside
> the IO monad, that just means running it.
>
>
> ‪On Sun, Dec 12, 2021 at 7:05 PM ‫יהושע ולך‬‎ 
> wrote:‬
>
>> Notice: (from ghci)
>>
>> Prelude GHC.Stack> :t callStack
>> callStack :: CallStack
>> Prelude GHC.Stack> :t getCallStack
>> getCallStack :: CallStack -> [([Char], SrcLoc)]
>> Prelude GHC.Stack> :t getCallStack callStack
>> getCallStack callStack :: [([Char], SrcLoc)]
>> Prelude GHC.Stack> :t length (getCallStack callStack)
>> length (getCallStack callStack) :: Int
>>
>> Prelude GHC.Stack> :t print (length (getCallStack callStack))
>> print (length (getCallStack callStack)) :: IO ()
>>
>> Prelude GHC.Stack> :t print
>> print :: Show a => a -> IO ()
>>
>>
>> the `print` function takes a pure value, and creates an IO value from it.
>> (actually printing is an IO action. the value it prints is not)
>>
>>
>>
>> On Sun, Dec 12, 2021 at 5:32 PM Michael Turner <
>> michael.eugene.tur...@gmail.com> wrote:
>>
>>> Regards,
>>> Michael Turner
>>> Executive Director
>>> Project Persephone
>>> 1-25-33 Takadanobaba
>>>
>>> Shinjuku-ku Tokyo 169-0075
>>> Mobile: +81 (90) 5203-8682
>>> tur...@projectpersephone.org
>>>
>>> Understand - http://www.projectpersephone.org/
>>> Join - http://www.facebook.com/groups/ProjectPersephone/
>>> Donate - http://www.patreon.com/ProjectPersephone
>>> Volunteer - https://github.com/ProjectPersephone
>>>
>>> "Love does not consist in gazing at each other, but in looking outward
>>> together in the same direction." -- Antoine de Saint-Exupéry
>>>
>>>
>>>
>>>
>>> On Sun, Dec 12, 2021 at 8:48 PM  wrote:
>>>
>>>
>>> > have another look at
>>> >
>>> https://hackage.haskell.org/packaggetCallStackgetCallStacke/base-4.16.0.0/docs/GHC-Stack.html#v:callStack
>>> > <
>>> https://hackage.haskell.org/package/base-4.16.0.0/docs/GHC-Stack.html#v:callStack
>>> >
>>>
>>> I'd been looking at that already, over and over. Still not seeing it.
>>> But your proposed fix does work. Thank you.
>>> > let l = getCallStack callStack
>>> > print (length l)
>>> > ```
>>> > the `getCallStack` does not return an "IO" value..
>>>
>>> And yet it's it's somehow an IO value in "print (length (getCallStack
>>> callStack))"?
>>>
>>> I just don't get this.
>>>
>>> > On Sun, Dec 12, 2021, 12:58 Michael Turner <
>>> michael.eugene.tur...@gmail.com>
>>> > wrote:
>>> >
>>> > > The following prints 1, as you'd expect:
>>> > > -
>>> > > import GHC.Stack
>>> > >
>>> > > foo :: HasCallStack => IO ()
>>> > > foo = do
>>> > >print (length (getCallStack callStack))
>>> > >
>>> > > main =
>>> > >   foo
>>> > > ---
>>> > > But when I make it this:
>>> > > ...
>>> > >l <- getCallStack callStack ;
>>> > >print (length l)
>>> > >
>>> > >  I get all this:
>>> > > --
>>> > > ...
>>> > > • Couldn't match type ‘[]’ with ‘IO’
>>> > >   Expected type: IO ([Char], SrcLoc)
>>> > > Actual type: [([Char], SrcLoc)]
>>> > > • In a stmt of a 'do' block: l <- getCallStack callStack
>>> > >   In the expression:
>>> > > do l <- getCallStack callStack
>>> > >print (length l)
>>> > >   In an equation for ‘foo’:
>>> > >   foo
>>> > > = do l <- getCallStack callStack
>>> > >  print (length l)
>>> > >   |
>>> > > 5 |l <- getCallStack callStack ;
>>> > >   | ^^
>>> > > 
>>> > >
>>> > > What am I not seeing?
>>> > >
>>> > >
>>> > > Regards,
>>> > > Michael Turner
>>> > > Executive Director
>>> > > Project Persephone
>>> > > 1-25-33 Takadanobaba
>>> > >
>>> > > 

Beginners Digest, Vol 161, Issue 2

2021-12-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Beginners Digest, Vol 161, Issue 1 (Michael Turner)
   2. Re:  Beginners Digest, Vol 161, Issue 1 (יהושע ולך)
   3. Re:  Beginners Digest, Vol 161, Issue 1 (יהושע ולך)


--

Message: 1
Date: Mon, 13 Dec 2021 00:31:34 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 161, Issue 1
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Regards,
Michael Turner
Executive Director
Project Persephone
1-25-33 Takadanobaba

Shinjuku-ku Tokyo 169-0075
Mobile: +81 (90) 5203-8682
tur...@projectpersephone.org

Understand - http://www.projectpersephone.org/
Join - http://www.facebook.com/groups/ProjectPersephone/
Donate - http://www.patreon.com/ProjectPersephone
Volunteer - https://github.com/ProjectPersephone

"Love does not consist in gazing at each other, but in looking outward
together in the same direction." -- Antoine de Saint-Exupéry




On Sun, Dec 12, 2021 at 8:48 PM  wrote:


> have another look at
> https://hackage.haskell.org/packaggetCallStackgetCallStacke/base-4.16.0.0/docs/GHC-Stack.html#v:callStack
> 

I'd been looking at that already, over and over. Still not seeing it.
But your proposed fix does work. Thank you.
> let l = getCallStack callStack
> print (length l)
> ```
> the `getCallStack` does not return an "IO" value..

And yet it's it's somehow an IO value in "print (length (getCallStack
callStack))"?

I just don't get this.

> On Sun, Dec 12, 2021, 12:58 Michael Turner 
> wrote:
>
> > The following prints 1, as you'd expect:
> > -
> > import GHC.Stack
> >
> > foo :: HasCallStack => IO ()
> > foo = do
> >print (length (getCallStack callStack))
> >
> > main =
> >   foo
> > ---
> > But when I make it this:
> > ...
> >l <- getCallStack callStack ;
> >print (length l)
> >
> >  I get all this:
> > --
> > ...
> > • Couldn't match type ‘[]’ with ‘IO’
> >   Expected type: IO ([Char], SrcLoc)
> > Actual type: [([Char], SrcLoc)]
> > • In a stmt of a 'do' block: l <- getCallStack callStack
> >   In the expression:
> > do l <- getCallStack callStack
> >print (length l)
> >   In an equation for ‘foo’:
> >   foo
> > = do l <- getCallStack callStack
> >  print (length l)
> >   |
> > 5 |l <- getCallStack callStack ;
> >   | ^^
> > 
> >
> > What am I not seeing?
> >
> >
> > Regards,
> > Michael Turner
> > Executive Director
> > Project Persephone
> > 1-25-33 Takadanobaba
> >
> > Shinjuku-ku Tokyo 169-0075
> > Mobile: +81 (90) 5203-8682
> > tur...@projectpersephone.org
> >
> > Understand - http://www.projectpersephone.org/
> > Join - http://www.facebook.com/groups/ProjectPersephone/
> > Donate - http://www.patreon.com/ProjectPersephone
> > Volunteer - https://github.com/ProjectPersephone
> >
> > "Love does not consist in gazing at each other, but in looking outward
> > together in the same direction." -- Antoine de Saint-Exupéry


--

Message: 2
Date: Sun, 12 Dec 2021 19:05:22 +0200
From: יהושע ולך 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 161, Issue 1
Message-ID:

Content-Type: text/plain; charset="utf-8"

Notice: (from ghci)

Prelude GHC.Stack> :t callStack
callStack :: CallStack
Prelude GHC.Stack> :t getCallStack
getCallStack :: CallStack -> [([Char], SrcLoc)]
Prelude GHC.Stack> :t getCallStack callStack
getCallStack callStack :: [([Char], SrcLoc)]
Prelude GHC.Stack> :t length (getCallStack callStack)
length (getCallStack callStack) :: Int

Prelude GHC.Stack> :t print (length (getCallStack callStack))
print (length (getCallStack callStack)) :: IO ()

Prelude GHC.Stack> :t print
print :: Show a => a -> IO ()


the `print` function takes a pure value, and creates an IO value from it.
(actually printing is an IO action. the value it prints is not)



On Sun, Dec 12, 2021 at 5:32 PM Michael Turner <
michael.eugene.tur...@gmail.com> wrote:

> Regards,
> Michael Turner
> Executive Director
> Project Persephone
> 1-25-33 Takadanobaba
>
> Shinjuku-ku Tokyo 169-0075
> Mobile: +81 (90) 

Beginners Digest, Vol 161, Issue 1

2021-12-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Non-exhaustive patterns (Galaxy Being)
   2. Re:  Non-exhaustive patterns (Pietro Grandinetti)
   3.  But I just want a function that returns stackdepth!
  (Michael Turner)
   4. Re:  But I just want a function that returns  stack depth!
  (יהושע ולך)


--

Message: 1
Date: Sat, 11 Dec 2021 23:14:03 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Non-exhaustive patterns
Message-ID:

Content-Type: text/plain; charset="utf-8"

This code

myTakePM :: Int -> [a] -> [a]
myTakePM 0 _ = []
myTakePM n (x:xs) = x : myTakePM (n-1) xs

is bad because it allows

myTakePM 4 [1,2,3]
 [1,2,3*** Exception: :(395,1)-(396,41): Non-exhaustive
patterns in function myTakePM

I knew it would not work, but why is it calling this essentially a partial
function? How does it know this? Again, I expected an error, but what is
this Non-exhaustive patterns in function myTakePM saying? Or, said another
way, what exactly is non-exhaustive about this?
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 12 Dec 2021 05:21:34 +
From: Pietro Grandinetti 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Non-exhaustive patterns
Message-ID:



Content-Type: text/plain; charset="utf-8"

Hello - I think the pattern for the empty list (as second argument) is missing.

From: Beginners  on behalf of Galaxy Being 

Sent: Sunday, December 12, 2021 6:14:03 AM
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level 
topics related to Haskell 
Subject: [Haskell-beginners] Non-exhaustive patterns

This code

myTakePM :: Int -> [a] -> [a]
myTakePM 0 _ = []
myTakePM n (x:xs) = x : myTakePM (n-1) xs

is bad because it allows

myTakePM 4 [1,2,3]
 [1,2,3*** Exception: :(395,1)-(396,41): Non-exhaustive patterns 
in function myTakePM

I knew it would not work, but why is it calling this essentially a partial 
function? How does it know this? Again, I expected an error, but what is this 
Non-exhaustive patterns in function myTakePM saying? Or, said another way, what 
exactly is non-exhaustive about this?
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Sun, 12 Dec 2021 19:57:03 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: [Haskell-beginners] But I just want a function that returns
stack   depth!
Message-ID:

Content-Type: text/plain; charset="UTF-8"

The following prints 1, as you'd expect:
-
import GHC.Stack

foo :: HasCallStack => IO ()
foo = do
   print (length (getCallStack callStack))

main =
  foo
---
But when I make it this:
...
   l <- getCallStack callStack ;
   print (length l)

 I get all this:
--
...
• Couldn't match type ‘[]’ with ‘IO’
  Expected type: IO ([Char], SrcLoc)
Actual type: [([Char], SrcLoc)]
• In a stmt of a 'do' block: l <- getCallStack callStack
  In the expression:
do l <- getCallStack callStack
   print (length l)
  In an equation for ‘foo’:
  foo
= do l <- getCallStack callStack
 print (length l)
  |
5 |l <- getCallStack callStack ;
  | ^^


What am I not seeing?


Regards,
Michael Turner
Executive Director
Project Persephone
1-25-33 Takadanobaba

Shinjuku-ku Tokyo 169-0075
Mobile: +81 (90) 5203-8682
tur...@projectpersephone.org

Understand - http://www.projectpersephone.org/
Join - http://www.facebook.com/groups/ProjectPersephone/
Donate - http://www.patreon.com/ProjectPersephone
Volunteer - https://github.com/ProjectPersephone

"Love does not consist in gazing at each other, but in 

Beginners Digest, Vol 160, Issue 2

2021-11-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Monad question (Kim-Ee Yeoh)


--

Message: 1
Date: Fri, 26 Nov 2021 01:55:42 +0700
From: Kim-Ee Yeoh 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Monad question
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hi Mike,

On Fri, Nov 26, 2021 at 12:12 AM mike h  wrote:

>
> I have
> data Expr a = Var a | Add (Expr a) (Expr a)
>
> and would like to write
>
> convert :: Expr (Maybe a) -> Maybe (Expr a)


With the requisite setup, convert has a one word definition. But more on
that later.

Yehoshua has already given you a nudge in the right direction. Others will
surely chime in if you get stuck grinding out something the compiler will
type check.

What we could discuss is higher level. Where would use this convert
function? What utility could you obtain from it?



>
> which returns Nothing if there is an occurrence of Nothing inside the
> input expression e, otherwise it returns Just e', where e'
> is a new expression where the internal values of type a are not wrapped in
> Just.
> You should use the functionality of the Maybe monad to implement
> the convert function.
>
>
> Thanks
> Mike
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
-- Kim-Ee
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 160, Issue 2
*


Beginners Digest, Vol 160, Issue 1

2021-11-25 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Monad  question (mike h)
   2. Re:  Monad question (יהושע ולך)
   3. Re:  Monad question (יהושע ולך)
   4. Re:  Monad question (יהושע ולך)
   5. Re:  Monad question (Imants Cekusins)


--

Message: 1
Date: Thu, 25 Nov 2021 17:10:44 +
From: mike h 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Monad  question
Message-ID: 
Content-Type: text/plain;   charset=utf-8

Hi,
This isn’t homework! I’ve been staring at this for several hours - and that 
usually works.
I also tried typed holes to no avail.  I thinks it is  quite simple really but 
I’ve gone past seeing it!

I have 
data Expr a = Var a | Add (Expr a) (Expr a) 

and would like to write

convert :: Expr (Maybe a) -> Maybe (Expr a)

which returns Nothing if there is an occurrence of Nothing inside the
input expression e, otherwise it returns Just e', where e'
is a new expression where the internal values of type a are not wrapped in Just.
You should use the functionality of the Maybe monad to implement
the convert function. 


Thanks 
Mike

--

Message: 2
Date: Thu, 25 Nov 2021 19:46:05 +0200
From: יהושע ולך 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Monad question
Message-ID:

Content-Type: text/plain; charset="utf-8"

I can't actually cheok right now,
but
```
convert (Var mv) = do
v <- mv
 return $ Var v
```

is the "do notation" which should work.
(and similarly for the other expression)

On Thu, Nov 25, 2021, 19:13 mike h  wrote:

> Hi,
> This isn’t homework! I’ve been staring at this for several hours - and
> that usually works.
> I also tried typed holes to no avail.  I thinks it is  quite simple really
> but I’ve gone past seeing it!
>
> I have
> data Expr a = Var a | Add (Expr a) (Expr a)
>
> and would like to write
>
> convert :: Expr (Maybe a) -> Maybe (Expr a)
>
> which returns Nothing if there is an occurrence of Nothing inside the
> input expression e, otherwise it returns Just e', where e'
> is a new expression where the internal values of type a are not wrapped in
> Just.
> You should use the functionality of the Maybe monad to implement
> the convert function.
>
>
> Thanks
> Mike
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Thu, 25 Nov 2021 19:53:41 +0200
From: יהושע ולך 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Monad question
Message-ID:

Content-Type: text/plain; charset="utf-8"

convert (Var mx) = mx >>= (return .Var x)

Should also be the non-do-notation.
(again, typing from a phone, and not tested)

On Thu, Nov 25, 2021, 19:46 יהושע ולך  wrote:

> I can't actually cheok right now,
> but
> ```
> convert (Var mv) = do
> v <- mv
>  return $ Var v
> ```
>
> is the "do notation" which should work.
> (and similarly for the other expression)
>
> On Thu, Nov 25, 2021, 19:13 mike h  wrote:
>
>> Hi,
>> This isn’t homework! I’ve been staring at this for several hours - and
>> that usually works.
>> I also tried typed holes to no avail.  I thinks it is  quite simple
>> really but I’ve gone past seeing it!
>>
>> I have
>> data Expr a = Var a | Add (Expr a) (Expr a)
>>
>> and would like to write
>>
>> convert :: Expr (Maybe a) -> Maybe (Expr a)
>>
>> which returns Nothing if there is an occurrence of Nothing inside the
>> input expression e, otherwise it returns Just e', where e'
>> is a new expression where the internal values of type a are not wrapped
>> in Just.
>> You should use the functionality of the Maybe monad to implement
>> the convert function.
>>
>>
>> Thanks
>> Mike
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
-- next part --
An HTML attachment was scrubbed...
URL: 

Beginners Digest, Vol 159, Issue 2

2021-10-20 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Looking for training (Pratap Pachipulusu)
   2. Re:  Looking for training (Pratap Pachipulusu)
   3. Re:  Looking for training (Pratap Pachipulusu)
   4. Re:  Looking for training (Pratap Pachipulusu)
   5. Re:  Looking for training (Fernando Basso)


--

Message: 1
Date: Tue, 19 Oct 2021 20:58:18 -0400
From: Pratap Pachipulusu 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

Dear Frank,

My programming language is Java/Scala. I am basically Spark/Scala
developer, i fell in love with functional programming language while
working on spark/scala. I want to know why functional programming is
suitable for bigdata processing(in depth)

Thank you
Pratap P.

On Mon, Oct 18, 2021 at 7:35 PM Frank Martinez 
wrote:

> What is Your programming background?
>
> On Mon, Oct 18, 2021 at 19:10 Pratap Pachipulusu 
> wrote:
>
>> Hello Members,
>>
>> Could you please suggest good haskell resources to start learning from
>> scratch. I would love to be on top of it.
>>
>> Thanks,
>> Pratap P.
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> --
> P.S.: I prefer to be reached on BitMessage at
> BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 19 Oct 2021 20:58:58 -0400
From: Pratap Pachipulusu 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

Thank you Mukesh!!

On Mon, Oct 18, 2021 at 7:43 PM mukesh tiwari 
wrote:

> Try http://learnyouahaskell.com/. I found it very helpful when I was
> learning Haskell. In addition, try to solve problems because it will force
> you to think in Haskell.
>
> Best,
> Mukesh
>
> On Tue, Oct 19, 2021 at 10:11 AM Pratap Pachipulusu <
> pratap.hask...@gmail.com> wrote:
>
>> Hello Members,
>>
>> Could you please suggest good haskell resources to start learning from
>> scratch. I would love to be on top of it.
>>
>> Thanks,
>> Pratap P.
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Tue, 19 Oct 2021 20:59:52 -0400
From: Pratap Pachipulusu 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

Thank you Frank!!

On Mon, Oct 18, 2021 at 7:51 PM Frank Martinez 
wrote:

> LYAH is definitely good; the only downside is making sure You completely
> forget everything You know about programming first, a task which can be
> difficult for some.
>
> On Mon, Oct 18, 2021 at 19:42 mukesh tiwari 
> wrote:
>
>> Try http://learnyouahaskell.com/. I found it very helpful when I was
>> learning Haskell. In addition, try to solve problems because it will force
>> you to think in Haskell.
>>
>> Best,
>> Mukesh
>>
>> On Tue, Oct 19, 2021 at 10:11 AM Pratap Pachipulusu <
>> pratap.hask...@gmail.com> wrote:
>>
>>> Hello Members,
>>>
>>> Could you please suggest good haskell resources to start learning from
>>> scratch. I would love to be on top of it.
>>>
>>> Thanks,
>>> Pratap P.
>>> ___
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> 

Beginners Digest, Vol 159, Issue 1

2021-10-19 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Looking for training (Pratap Pachipulusu)
   2. Re:  Looking for training (Frank Martinez)
   3. Re:  Looking for training (mukesh tiwari)
   4. Re:  Looking for training (Frank Martinez)
   5. Re:  Looking for training (Francesco Ariis)


--

Message: 1
Date: Mon, 18 Oct 2021 19:10:17 -0400
From: Pratap Pachipulusu 
To: beginners@haskell.org
Subject: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello Members,

Could you please suggest good haskell resources to start learning from
scratch. I would love to be on top of it.

Thanks,
Pratap P.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Mon, 18 Oct 2021 19:35:03 -0400
From: Frank Martinez 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

What is Your programming background?

On Mon, Oct 18, 2021 at 19:10 Pratap Pachipulusu 
wrote:

> Hello Members,
>
> Could you please suggest good haskell resources to start learning from
> scratch. I would love to be on top of it.
>
> Thanks,
> Pratap P.
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
P.S.: I prefer to be reached on BitMessage at
BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Tue, 19 Oct 2021 10:42:07 +1100
From: mukesh tiwari 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

Try http://learnyouahaskell.com/. I found it very helpful when I was
learning Haskell. In addition, try to solve problems because it will force
you to think in Haskell.

Best,
Mukesh

On Tue, Oct 19, 2021 at 10:11 AM Pratap Pachipulusu <
pratap.hask...@gmail.com> wrote:

> Hello Members,
>
> Could you please suggest good haskell resources to start learning from
> scratch. I would love to be on top of it.
>
> Thanks,
> Pratap P.
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 4
Date: Mon, 18 Oct 2021 19:51:03 -0400
From: Frank Martinez 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Looking for training
Message-ID:

Content-Type: text/plain; charset="utf-8"

LYAH is definitely good; the only downside is making sure You completely
forget everything You know about programming first, a task which can be
difficult for some.

On Mon, Oct 18, 2021 at 19:42 mukesh tiwari 
wrote:

> Try http://learnyouahaskell.com/. I found it very helpful when I was
> learning Haskell. In addition, try to solve problems because it will force
> you to think in Haskell.
>
> Best,
> Mukesh
>
> On Tue, Oct 19, 2021 at 10:11 AM Pratap Pachipulusu <
> pratap.hask...@gmail.com> wrote:
>
>> Hello Members,
>>
>> Could you please suggest good haskell resources to start learning from
>> scratch. I would love to be on top of it.
>>
>> Thanks,
>> Pratap P.
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
P.S.: I prefer to be reached on BitMessage at
BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6
-- next part --
An HTML attachment was 

Beginners Digest, Vol 158, Issue 5

2021-09-20 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Type signatures returned with :t (Erik Dominikus)
   2. Re:  Type signatures returned with :t (Joel Neely)


--

Message: 1
Date: Sun, 19 Sep 2021 19:54:30 +0700
From: Erik Dominikus 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:

Content-Type: text/plain; charset="utf-8"

> are both straightforward parameterized types, but Maybe doesn't give me a
type parameter back, while Either does, and in different order, different
names (a becomes b; b becomes a) depending on which variable I invoke.

Try these diagnostics:

--- Diagnostic 1

Given that the type of "const" is "a -> b -> a" and the type of "True" is
"Bool":

:t const
const :: a -> b -> a

:t True
True :: Bool

What do you expect the type of "const True" to be?

:t const True
const True :: 

   - If you answer "b -> Bool", you are correct, so you may be confused by
   the data type definition syntax (see below).
   - If you answer something else, you may be missing some basic
   understanding of the type system.


--- Diagnostic 2

Consider this case:

:t id
id :: a -> a

:t (id, id)
(id, id) :: (a1 -> a1, a2 -> a2)

   - If you think that the type of "(id, id)" should be "(a -> a, a -> a)",
   you may be unaware of the implicit universal quantifiers.


--- If you are confused by the data type definition syntax:

data Either a b
  = Left a
  | Right b

then, consider the GADT (generalized algebraic data type) definition syntax
for saying the same thing:

data Either a b where
  Left  :: a -> Either a b
  Right :: b -> Either a b

The problem becomes less confusing: The GADT definition syntax is screaming
that "Left" is a function like "id", "const", etc.

---

If you're still unsure, try thinking aloud here: Write your expectations
and why you think so (your thought process, what steps you took to arrive
at your expectations).
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 19 Sep 2021 12:13:59 -0500
From: Joel Neely 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:

Content-Type: text/plain; charset="utf-8"

I hope the wizards will forgive a down-to-earth analogy.

Either a b is a knapsack with two pockets, the one on the Left (which must
hold an "a") and the one on the Right (which must hold a "b"). But you can
only use one pocket at a time.

So when there's a specific case of Either a b such as Left True, all that
can be concluded is that this is a case of an Either whose left pocket must
be able to handle a Bool; there's not enough information to know what could
have been put in the Right pocket. So only the left-pocket type ("a") can
be replaced with something specific.

Similarly, for a specific case of Right False, it's clear that the right
pocket holds a value of type Bool (replacing the general "b"), but there's
no information to identify what type might be in the left pocket. So it
remains unspecified.

I hope that helps.
-jn-

On Sat, Sep 18, 2021 at 9:21 PM Galaxy Being  wrote:

> Either returns with its parameters, reversed, but Maybe did not. That's my
> main question.
>
> On Sat, Sep 18, 2021 at 5:43 PM Francesco Ariis  wrote:
>
>> Il 18 settembre 2021 alle 17:30 Galaxy Being ha scritto:
>> > > :t Just True
>> > Just True :: Maybe Bool
>> > > :t Left True
>> > Left True :: Either Bool b
>> > > :t Right False
>> > Right False :: Either a Bool
>> >
>> > What am I being told here? It seems
>> > are both straightforward parameterized types, but Maybe doesn't give me
>> a
>> > type parameter back, while Either does, and in different order,
>> different
>> > names (a becomes b; b becomes a) depending on which variable I invoke.
>> What
>> > deeper lore am I not seeing here?
>>
>> When you ask the type of
>>
>> λ> :t Just True
>>
>> the interpreter *knows* that that `Maybe` is not just a `Maybe a` (so
>> type constructor and its type parameter) but the /concrete/ type `Maybe
>> Bool`. This would not be the case if we did
>>
>> λ> :t Nothing
>> Nothing :: Maybe a
>>
>> 

Beginners Digest, Vol 158, Issue 4

2021-09-19 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Type signatures returned with :t (Galaxy Being)
   2. Re:  Type signatures returned with :t (Francesco Ariis)
   3. Re:  Type signatures returned with :t (Galaxy Being)
   4. Re:  Type signatures returned with :t (Erik Dominikus)
   5. Re:  Type signatures returned with :t (Andreas Perstinger)


--

Message: 1
Date: Sat, 18 Sep 2021 17:30:17 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Type signatures returned with :t
Message-ID:

Content-Type: text/plain; charset="utf-8"

> :t Just True
Just True :: Maybe Bool
> :t Left True
Left True :: Either Bool b
> :t Right False
Right False :: Either a Bool

What am I being told here? It seems

data Maybe a = Just a
 | Nothing
data Either a b = Left a
| Right b

are both straightforward parameterized types, but Maybe doesn't give me a
type parameter back, while Either does, and in different order, different
names (a becomes b; b becomes a) depending on which variable I invoke. What
deeper lore am I not seeing here?


-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 19 Sep 2021 00:41:58 +0200
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID: 
Content-Type: text/plain; charset=utf-8

Il 18 settembre 2021 alle 17:30 Galaxy Being ha scritto:
> > :t Just True
> Just True :: Maybe Bool
> > :t Left True
> Left True :: Either Bool b
> > :t Right False
> Right False :: Either a Bool
> 
> What am I being told here? It seems
> are both straightforward parameterized types, but Maybe doesn't give me a
> type parameter back, while Either does, and in different order, different
> names (a becomes b; b becomes a) depending on which variable I invoke. What
> deeper lore am I not seeing here?

When you ask the type of

λ> :t Just True

the interpreter *knows* that that `Maybe` is not just a `Maybe a` (so
type constructor and its type parameter) but the /concrete/ type `Maybe
Bool`. This would not be the case if we did

λ> :t Nothing
Nothing :: Maybe a

Same story with `Either`. Each of the two data constructors (`Left` and
`Right`) let the interpreter infer just *one* of the type parameters
(the `a` and `b` in `Either a b`).
Does this answer your question?


--

Message: 3
Date: Sat, 18 Sep 2021 21:19:09 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:

Content-Type: text/plain; charset="utf-8"

Either returns with its parameters, reversed, but Maybe did not. That's my
main question.

On Sat, Sep 18, 2021 at 5:43 PM Francesco Ariis  wrote:

> Il 18 settembre 2021 alle 17:30 Galaxy Being ha scritto:
> > > :t Just True
> > Just True :: Maybe Bool
> > > :t Left True
> > Left True :: Either Bool b
> > > :t Right False
> > Right False :: Either a Bool
> >
> > What am I being told here? It seems
> > are both straightforward parameterized types, but Maybe doesn't give me a
> > type parameter back, while Either does, and in different order, different
> > names (a becomes b; b becomes a) depending on which variable I invoke.
> What
> > deeper lore am I not seeing here?
>
> When you ask the type of
>
> λ> :t Just True
>
> the interpreter *knows* that that `Maybe` is not just a `Maybe a` (so
> type constructor and its type parameter) but the /concrete/ type `Maybe
> Bool`. This would not be the case if we did
>
> λ> :t Nothing
> Nothing :: Maybe a
>
> Same story with `Either`. Each of the two data constructors (`Left` and
> `Right`) let the interpreter infer just *one* of the type parameters
> (the `a` and `b` in `Either a b`).
> Does this answer your question?
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part 

Beginners Digest, Vol 158, Issue 3

2021-09-17 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  A one- or two-page diagram of how Haskellworks?
  (Anthony Clayden)


--

Message: 1
Date: Fri, 17 Sep 2021 10:00:18 +1200
From: Anthony Clayden 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] A one- or two-page diagram of how
Haskell works?
Message-ID:

Content-Type: text/plain; charset="utf-8"

Thank you Tarik, you're spot-on correct.

> It's better to try to model execution using lambda calculus.

> The most dominant factor in languages like Haskell is lambda calculus.
> Think through lambda calculus for a mental model.


I presume it's this advice that Michael is complaining about in his
long comment on the cafe yesterday.

In particular, Haskell is unusual even amongst functional programming
languages in its lazy evaluation. So to try to correct Michael's
misunderstanding:


>> When I write C, or even C++, I have a mental model of how execution will 
>> proceed.


Firstly, 'execution' in Haskell does not proceed in anything like the
sequence-of-steps and update-of-locations/frame-on-the-stack of C or C++
(or Fortran or ALGOL or COBOL or ...). In particular, 'variables' in
Haskell are not overwritable locations in the sense of a procedural
language. Variables are just a name for an expression (might be a lambda
expression). This is what we mean by 'referential transparency' that
procedural languages do not have. We can replace any variable by the
expression it denotes, or by any other equivalent expression.

Secondly, there's an important theorem (Church-Rosser) in Lambda calculus
[see wikipedia], that if Beta-reduction terminates, it'll produce the same
'reduced form' of the initial expression whether it proceeds inside-out or
outside-in or both-sides-to-the-middle. You don't need to second-guess how
the compiler proceeds, because you don't need to know.

You do need to understand Beta-reduction (that's easy). You also need to
understand why Alpha-renaming is needed hand-in-hand with Beta-reduction
(not so easy, but work a few examples with a recursive function, such as
stepping through a list).

And you need to stop immediately trying to imagine Haskell semantics as
some sort of crazy Turing machine: you'll go mad. Turing himself [1937]
proved the semantics are equivalent; but that paper is impenetrable for
ordinary mortals like me.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 158, Issue 3
*


Beginners Digest, Vol 158, Issue 2

2021-09-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Confusing Show/print error (Fernando Basso)


--

Message: 1
Date: Sun, 12 Sep 2021 07:57:38 -0300
From: Fernando Basso 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Confusing Show/print error
Message-ID: <20210912105738.egomltlkquv5l...@gmail.com>
Content-Type: text/plain; charset=utf-8

Hi Lawrence.

Other people have given some answers, but perhaps saying it in a
different way may also help.

For starters, we have to remember that functions do not have instances
of `Show' [1]:

To exemplify, if we have a function and try to print it, we get an error:

f :: a -> a
f x = x

$ ghci

Prelude> :load fn.hs
*Main> f

:2:1: error:
• No instance for (Show (a0 -> a0)) arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of an interactive GHCi command: print it
*Main>

This is just to exemplify that there is nothing wrong with *your*
function. As you see, I produced the same error with a much simpler
function. So, as others mentioned, it looks like you just tried to print
your function, which is not possible.

I would also like to add a note about emacs haskell-mode's REPL that is
related to this topic. haskell-mode's REPL runs `:type' behind the
scenes when we try to print functions. It might give the impression that
we can actually print functions, or that functions have instance of
`Show', which is not the case.

In emacs + haskell-mode, the variable

haskell-interactive-types-for-show-ambiguous

is supposed to be `t' by default (instead of `nil'). In any case, you
can play with it and try to print functions directly by just typing
their name [2]:

(custom-set-variables
  '(haskell-interactive-types-for-show-ambiguous t)

References:

• [1] https://wiki.haskell.org/Show_instance_for_functions
• [2] 
https://haskell.github.io/haskell-mode/manual/latest/Interactive-Haskell.html#Type-of-expressions

On Thu, Sep 09, 2021 at 04:25:58PM -0500, Galaxy Being wrote:
> I've got this
> 
> import Data.Tuple
> fswp :: (a, b) -> (b, a)
> fswp = Data.Tuple.swap
> 
> and get this
> 
>  • No instance for (Show ((a0, b0) -> (b0, a0)))
> arising from a use of ‘print’
> (maybe you haven't applied a function to enough arguments?)
> • In a stmt of an interactive GHCi command: print it
> 
> Not sure why or what to do to correct it.
> 
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com

> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 158, Issue 2
*


Beginners Digest, Vol 158, Issue 1

2021-09-10 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Confusing Show/print error (Galaxy Being)
   2. Re:  Confusing Show/print error (Francesco Ariis)
   3. Re:  Confusing Show/print error (Tobias Brandt)


--

Message: 1
Date: Thu, 9 Sep 2021 16:25:58 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Confusing Show/print error
Message-ID:

Content-Type: text/plain; charset="utf-8"

I've got this

import Data.Tuple
fswp :: (a, b) -> (b, a)
fswp = Data.Tuple.swap

and get this

 • No instance for (Show ((a0, b0) -> (b0, a0)))
arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of an interactive GHCi command: print it

Not sure why or what to do to correct it.

⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Thu, 9 Sep 2021 23:51:38 +0200
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Confusing Show/print error
Message-ID: 
Content-Type: text/plain; charset=utf-8

Hello Lawrence,

Il 09 settembre 2021 alle 16:25 Galaxy Being ha scritto:
> import Data.Tuple
> fswp :: (a, b) -> (b, a)
> fswp = Data.Tuple.swap

this typechecks without problem.

maybe you invoked fswp without an argument? (i.e. `λ> fwsp`
instead of `λ> fwsp (1,'a')`)


--

Message: 3
Date: Thu, 9 Sep 2021 23:56:58 +0200
From: Tobias Brandt 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Confusing Show/print error
Message-ID: <4c9f37b6-c3d2-30f6-aa1a-2466cd01e...@uni-bremen.de>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi Lawrence,

it seems that you are trying to print your defined function. Most likely 
you just forgot to apply an argument to fswp. So 'fswp (1,2)' should 
just work fine.

Cheers,

Tobias

On 9/9/21 11:25 PM, Galaxy Being wrote:
> I've got this
>
> import Data.Tuple
> fswp :: (a, b) -> (b, a)
> fswp = Data.Tuple.swap
>
> and get this
>
> • No instance for (Show ((a0, b0) -> (b0, a0)))
>         arising from a use of ‘print’
>         (maybe you haven't applied a function to enough arguments?)
>     • In a stmt of an interactive GHCi command: print it
>
> Not sure why or what to do to correct it.
>
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com 
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 158, Issue 1
*


Beginners Digest, Vol 157, Issue 1

2021-08-01 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  A one- or two-page diagram of how Haskellworks?
  (c...@coot.me)


--

Message: 1
Date: Sat, 31 Jul 2021 14:49:16 +
From: c...@coot.me
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] A one- or two-page diagram of how
Haskell works?
Message-ID:



Content-Type: text/plain; charset="utf-8"

I recently wrote a blog post which explains how expressions are evaluated: 
https://coot.me/posts/containers-strict-foldr.html

Best regards,
Marcin

Sent with ProtonMail Secure Email.

‐‐‐ Original Message ‐‐‐

On Thursday, June 24th, 2021 at 05:41, Michael Turner 
 wrote:

> When I write C, or even C++, I have a mental model of how execution
> 

> will proceed.
> 

> When I write Prolog, but get confused, I run a kind of skeletal
> 

> inference algorithm in my head and the confusion usually clears up. I
> 

> can imagine how things are stored and what's done with them. I can see
> 

> /through/ the code to the machine.
> 

> With Haskell, I still feel blind.
> 

> Has anyone summarized it all in a chart where I can look at it and
> 

> think, "Ah, OK, GHC is taking this line and thinking of it THIS way"?
> 

> If someone wanted to write an interpreter for Haskell, would there be
> 

> a way for them to see how it would basically need to work, in one
> 

> chart?
> 

> Regards,
> 

> Michael Turner
> 

> Executive Director
> 

> Project Persephone
> 

> 1-25-33 Takadanobaba
> 

> Shinjuku-ku Tokyo 169-0075
> 

> Mobile: +81 (90) 5203-8682
> 

> tur...@projectpersephone.org
> 

> Understand - http://www.projectpersephone.org/
> 

> Join - http://www.facebook.com/groups/ProjectPersephone/
> 

> Donate - http://www.patreon.com/ProjectPersephone
> 

> Volunteer - https://github.com/ProjectPersephone
> 

> "Love does not consist in gazing at each other, but in looking outward
> 

> together in the same direction." -- Antoine de Saint-Exupéry
> 

> Beginners mailing list
> 

> Beginners@haskell.org
> 

> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 509 bytes
Desc: OpenPGP digital signature
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 157, Issue 1
*


Beginners Digest, Vol 156, Issue 5

2021-07-20 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Ratio data constructor (Bob Ippolito)
   2. Re:  Ratio data constructor (Galaxy Being)
   3. Re:  Ratio data constructor (Bob Ippolito)


--

Message: 1
Date: Tue, 20 Jul 2021 14:36:41 -0700
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Ratio data constructor
Message-ID:

Content-Type: text/plain; charset="utf-8"

Yes, the (%) function is a smart constructor for Data.Ratio because the
(:%) constructor is not exported. Other examples of this smart constructor
technique would be modules like Data.Set or Data.Map.

A smart constructor means that the module that defines the type does not
export its data constructor(s), making the implementation details
opaque, generally because the author wanted to be able to make assumptions
about the implementation that are not enforced by the type system. In this
case, they wanted all Ratio to be in reduced form. This makes many
operations faster or trivial, e.g. implementing Eq only requires comparing
the numerators and denominators. More information about the technique is
here: https://wiki.haskell.org/Smart_constructors



On Tue, Jul 20, 2021 at 2:17 PM Galaxy Being  wrote:

> ... does the last question have to do with a "smart constructor" by
> chance? If so, how?
>
> On Tue, Jul 20, 2021 at 3:42 PM Galaxy Being  wrote:
>
>> I'm investigating rational numbers with Haskell. This is the source I've
>> found
>>
>> data Ratio a = !a :% !a deriving (Eq)
>>
>> reduce ::  (Integral a) => a -> a -> Ratio a
>> {-# SPECIALISE reduce :: Integer -> Integer -> Rational #-}
>> reduce _ 0  =  ratioZeroDenominatorError
>> reduce x y  =  (x `quot` d) :% (y `quot` d)
>>where d = gcd x y
>> (%) :: (Integral a) => a -> a -> Ratio a
>> x % y =  reduce (x * signum y) (abs y)
>>
>> The Ratio data type would seem to be a parameterized type with two
>> parameters of the same type that must be "settled" in that they're not to
>> be lazily dealt with. Then the :% is the data constructor, the : meaning
>> it's a data constructor and not just an operation function. So this could
>> have been
>>
>> data Ratio a = :% !a !a deriving (Eq)
>>
>> correct? But then what confuses me is in reduce, why
>>
>> reduce x y  =  (x `quot` d) :% (y `quot` d)
>>
>> and not just %? We have :% defined in the data type and then (%) defined
>> as a function. What is going on here?
>>
>> --
>> ⨽
>> Lawrence Bottorff
>> Grand Marais, MN, USA
>> borg...@gmail.com
>>
>
>
> --
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 20 Jul 2021 17:09:56 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Ratio data constructor
Message-ID:

Content-Type: text/plain; charset="utf-8"

Yes, I see here
 that
the module Data.Ratio exports this

module  Data.Ratio (
Ratio, Rational, (%), numerator, denominator, approxRational ) where

which doesn't include :%.  But then I see numerator and denominator which
do have :%. But then to use them, this, e.g., won't work

numerator (60 20)

It needs the %

numerator (60 % 20)

So internally, :% is used, but users can never use :%, only %, which sends
things through reduce first. I could write my own version of Ratio that
didn't hide : and that would be okay. Have I got this right?



On Tue, Jul 20, 2021 at 4:37 PM Bob Ippolito  wrote:

> Yes, the (%) function is a smart constructor for Data.Ratio because the
> (:%) constructor is not exported. Other examples of this smart constructor
> technique would be modules like Data.Set or Data.Map.
>
> A smart constructor means that the module that defines the type does not
> export its data constructor(s), making the implementation details
> opaque, generally because the author wanted to be 

Beginners Digest, Vol 156, Issue 4

2021-07-20 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Ratio data constructor (Galaxy Being)
   2. Re:  Ratio data constructor (Galaxy Being)
   3. Re:  Ratio data constructor (Bob Ippolito)
   4. Re:  Ratio data constructor (David McBride)


--

Message: 1
Date: Tue, 20 Jul 2021 15:42:45 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Ratio data constructor
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm investigating rational numbers with Haskell. This is the source I've
found

data Ratio a = !a :% !a deriving (Eq)

reduce ::  (Integral a) => a -> a -> Ratio a
{-# SPECIALISE reduce :: Integer -> Integer -> Rational #-}
reduce _ 0  =  ratioZeroDenominatorError
reduce x y  =  (x `quot` d) :% (y `quot` d)
   where d = gcd x y
(%) :: (Integral a) => a -> a -> Ratio a
x % y =  reduce (x * signum y) (abs y)

The Ratio data type would seem to be a parameterized type with two
parameters of the same type that must be "settled" in that they're not to
be lazily dealt with. Then the :% is the data constructor, the : meaning
it's a data constructor and not just an operation function. So this could
have been

data Ratio a = :% !a !a deriving (Eq)

correct? But then what confuses me is in reduce, why

reduce x y  =  (x `quot` d) :% (y `quot` d)

and not just %? We have :% defined in the data type and then (%) defined as
a function. What is going on here?

-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 20 Jul 2021 16:16:55 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Ratio data constructor
Message-ID:

Content-Type: text/plain; charset="utf-8"

... does the last question have to do with a "smart constructor" by chance?
If so, how?

On Tue, Jul 20, 2021 at 3:42 PM Galaxy Being  wrote:

> I'm investigating rational numbers with Haskell. This is the source I've
> found
>
> data Ratio a = !a :% !a deriving (Eq)
>
> reduce ::  (Integral a) => a -> a -> Ratio a
> {-# SPECIALISE reduce :: Integer -> Integer -> Rational #-}
> reduce _ 0  =  ratioZeroDenominatorError
> reduce x y  =  (x `quot` d) :% (y `quot` d)
>where d = gcd x y
> (%) :: (Integral a) => a -> a -> Ratio a
> x % y =  reduce (x * signum y) (abs y)
>
> The Ratio data type would seem to be a parameterized type with two
> parameters of the same type that must be "settled" in that they're not to
> be lazily dealt with. Then the :% is the data constructor, the : meaning
> it's a data constructor and not just an operation function. So this could
> have been
>
> data Ratio a = :% !a !a deriving (Eq)
>
> correct? But then what confuses me is in reduce, why
>
> reduce x y  =  (x `quot` d) :% (y `quot` d)
>
> and not just %? We have :% defined in the data type and then (%) defined
> as a function. What is going on here?
>
> --
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
>


-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Tue, 20 Jul 2021 14:16:59 -0700
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Ratio data constructor
Message-ID:

Content-Type: text/plain; charset="utf-8"

On Tue, Jul 20, 2021 at 1:43 PM Galaxy Being  wrote:

> I'm investigating rational numbers with Haskell. This is the source I've
> found
>
> data Ratio a = !a :% !a deriving (Eq)
>
> reduce ::  (Integral a) => a -> a -> Ratio a
> {-# SPECIALISE reduce :: Integer -> Integer -> Rational #-}
> reduce _ 0  =  ratioZeroDenominatorError
> reduce x y  =  (x `quot` d) :% (y `quot` d)
>where d = gcd x y
> (%) :: (Integral a) => a 

Beginners Digest, Vol 156, Issue 3

2021-07-04 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Can't build project properly (Galaxy Being)


--

Message: 1
Date: Sat, 3 Jul 2021 16:57:54 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Can't build project properly
Message-ID:

Content-Type: text/plain; charset="utf-8"

Continue disregarding. Figured it out. Missing a language pragma.

On Fri, Jul 2, 2021 at 11:45 PM Galaxy Being  wrote:

> I'm trying to do a basic stack project named http-lesson (Chapter 39 from *Get
> Programming with Haskell) *which starts out with this in Main.hs
>
> module Main where
>
> import qualified Data.ByteString as B
> import qualified Data.ByteString.Char8 as BC
> import qualified Data.ByteString.Lazy as L
> import qualified Data.ByteString.Lazy.Char8 as LC
> import Network.HTTP.Simple
>
> After doing stack new http-lesson, the books says to modify the
> http-lesson.cabal file in the project, adding bytestring and http-conduit for
> the imports noted above
>
> executable http-lesson-exe
>   main-is: Main.hs
>   other-modules:
>   Paths_http_lesson
>   hs-source-dirs:
>   app
>   ghc-options: -threaded -rtsopts -with-rtsopts=-N
>   build-depends:
>   base >=4.7 && <5
> , http-lesson
> ,  bytestring
> , http-conduit
>   default-language: Haskell2010
>
> Being a beginner, I follow the cookbook-like directions, i.e., I next run 
> stack
> build . . . and it errors out, not finding the imported stuff. But then
> when I check the http-lesson.cabal file, the extra packages I added
> have been removed. Hunting around, I find this
> 
> that tells me to put the extra packages in package.yaml. Very confused at
> this point.
>
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
>


-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 156, Issue 3
*


Beginners Digest, Vol 156, Issue 2

2021-07-03 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Can't build project properly (Galaxy Being)


--

Message: 1
Date: Fri, 2 Jul 2021 23:45:21 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Can't build project properly
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm trying to do a basic stack project named http-lesson (Chapter 39 from *Get
Programming with Haskell) *which starts out with this in Main.hs

module Main where

import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.Char8 as LC
import Network.HTTP.Simple

After doing stack new http-lesson, the books says to modify the
http-lesson.cabal file in the project, adding bytestring and http-conduit for
the imports noted above

executable http-lesson-exe
  main-is: Main.hs
  other-modules:
  Paths_http_lesson
  hs-source-dirs:
  app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
  base >=4.7 && <5
, http-lesson
,  bytestring
, http-conduit
  default-language: Haskell2010

Being a beginner, I follow the cookbook-like directions, i.e., I next run stack
build . . . and it errors out, not finding the imported stuff. But then
when I check the http-lesson.cabal file, the extra packages I added
have been removed. Hunting around, I find this

that tells me to put the extra packages in package.yaml. Very confused at
this point.

⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 156, Issue 2
*


Beginners Digest, Vol 156, Issue 1

2021-07-02 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Date type needs helper function? (Galaxy Being)
   2. Re:  Date type needs helper function? (Matthew Low)


--

Message: 1
Date: Thu, 1 Jul 2021 11:41:21 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Date type needs helper function?
Message-ID:

Content-Type: text/plain; charset="utf-8"

I am using the built-in data type Day (Data.Time) in two ways

data PDate = PDate Day

or

type PDate Day

doesn't seem to matter. But then this doesn't work

testrec1 = PDate 2021 7 1

I always must use the "helper function" fromGregorian

testrec0 = PDate (fromGregorian 2021 7 1)
...
PDate 2021-07-01

Looking at Real World Haskell examples

data BookInfo = Book Int String [String]  deriving (Show)
...
myInfo = Book 9780135072455 "Algebra of Programming" ["Richard Bird", "Oege
de Moor"]

I know there's a great Haskell lesson to learn here, so why can Book take
everything naked but my Day version not?


⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Thu, 1 Jul 2021 11:41:11 -0600
From: Matthew Low 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Date type needs helper function?
Message-ID:

Content-Type: text/plain; charset="utf-8"

> why can Book take everything naked but my Day version not?

The Day data type is actually just a newtype wrapper around an Int, which
encodes the number of days since some point in the past - the docs more
details:
https://hackage.haskell.org/package/time-1.12/docs/Data-Time-Calendar.html.
So to use the data constructor directly as in the Book example, you'd have
to give it the number of days directly, something like ModifiedJulianDay
1234. The helper function gives a more convenient way to construct a Day. I
believe this general approach of having functions to help you construct a
data type is called 'smart constructors'. They're more common when the data
constructors are not exported from a module, so the helper functions are
the only way to create a value of that type - useful if you have some
constraints you need enforced on your type.

On Thu, Jul 1, 2021 at 10:41 AM Galaxy Being  wrote:

> I am using the built-in data type Day (Data.Time) in two ways
>
> data PDate = PDate Day
>
> or
>
> type PDate Day
>
> doesn't seem to matter. But then this doesn't work
>
> testrec1 = PDate 2021 7 1
>
> I always must use the "helper function" fromGregorian
>
> testrec0 = PDate (fromGregorian 2021 7 1)
> ...
> PDate 2021-07-01
>
> Looking at Real World Haskell examples
>
> data BookInfo = Book Int String [String]  deriving (Show)
> ...
> myInfo = Book 9780135072455 "Algebra of Programming" ["Richard Bird",
> "Oege de Moor"]
>
> I know there's a great Haskell lesson to learn here, so why can Book take
> everything naked but my Day version not?
>
>
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 156, Issue 1
*


Beginners Digest, Vol 155, Issue 11

2021-06-30 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Simple data type for dates? (Galaxy Being)
   2. Re:  Simple data type for dates? (Matthew Low)


--

Message: 1
Date: Tue, 29 Jun 2021 23:57:41 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Simple data type for dates?
Message-ID:

Content-Type: text/plain; charset="utf-8"

I've looked at Data.Time, but I'm not seeing examples. I'd like to figure
out how to simply have use of similar to this:

type MyMonth = String
type MyDay = String
type MyYear = String
data MyDate = MyDate MyMonth MyDay MyYear deriving Show

storeDate :: MyDate
storeDate = "June" "29" "2021"

which will be in a bigger data structure I'm building. I can't believe this
isn't reinventing some long-established wheel. Is there such a type ready
to use?

⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 29 Jun 2021 23:31:47 -0600
From: Matthew Low 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Simple data type for dates?
Message-ID:

Content-Type: text/plain; charset="utf-8"

The `time` package equivalent of `MyDate` would be `Day`:

storeDate :: Day
storeDate = fromGregorian 2021 6 29

> storeDate
2021-06-29
> toGregorian storeDate
(2021,6,29)
> dayOfWeek storeDate
Tuesday

However, I don't see any easy conversion between the numeric month and its
English name.


On Tue, Jun 29, 2021 at 10:58 PM Galaxy Being  wrote:

> I've looked at Data.Time, but I'm not seeing examples. I'd like to figure
> out how to simply have use of similar to this:
>
> type MyMonth = String
> type MyDay = String
> type MyYear = String
> data MyDate = MyDate MyMonth MyDay MyYear deriving Show
>
> storeDate :: MyDate
> storeDate = "June" "29" "2021"
>
> which will be in a bigger data structure I'm building. I can't believe
> this isn't reinventing some long-established wheel. Is there such a type
> ready to use?
>
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 11
**


Beginners Digest, Vol 155, Issue 10

2021-06-29 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Partial results with megaparsec (Dmitriy Matrosov)
   2. Re:  Partial results with megaparsec (David McBride)


--

Message: 1
Date: Mon, 28 Jun 2021 18:37:07 +0300
From: Dmitriy Matrosov 
To: beginners@haskell.org
Subject: [Haskell-beginners] Partial results with megaparsec
Message-ID: <1570a77d-1f0f-86cf-25a6-cda296488...@gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi.

I've used attoparsec before and it can return 'Partial' result containing
continuation, which is able to continue parsing if provided with more input.
E.g.

 > let A.Partial c1 = A.parse (A.string "mac address") "mac "; in c1 
"address"
 Done "" "mac address"

Does the same thing possible with megaparsec?

After looking through library API, i haven't find a way to do this.
'runParser' (which seems the only way to run megaparsec parser) fails on
incomplete (text) input.

And if that's not possible, how should i deal with chunked input?
E.g. i read from a socket with 'recv' and i don't want to read all
data at once. How can i suspend parsing for a time, read next chunk and
continue?

Thanks.



--

Message: 2
Date: Mon, 28 Jun 2021 12:46:16 -0400
From: David McBride 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Partial results with megaparsec
Message-ID:

Content-Type: text/plain; charset="utf-8"

Attoparsec was created specifically for streaming, thus its parsing
functions take into account that some portion of the pattern may yet to
have arrived and its combinators avoid taking input greedily
unintentionally.

It is not clear to me that megaparsec is capable of that. There is a
package attoparsec-parsec package, which reimplements parsec's combinators
in a way attoparsec can use, but I do not see a version of that for
megaparsec. You would have to write every megaparsec combinator into an
equivalent attoparsec to create such a package.

On Mon, Jun 28, 2021 at 11:37 AM Dmitriy Matrosov  wrote:

> Hi.
>
> I've used attoparsec before and it can return 'Partial' result containing
> continuation, which is able to continue parsing if provided with more
> input.
> E.g.
>
>  > let A.Partial c1 = A.parse (A.string "mac address") "mac "; in c1
> "address"
>  Done "" "mac address"
>
> Does the same thing possible with megaparsec?
>
> After looking through library API, i haven't find a way to do this.
> 'runParser' (which seems the only way to run megaparsec parser) fails on
> incomplete (text) input.
>
> And if that's not possible, how should i deal with chunked input?
> E.g. i read from a socket with 'recv' and i don't want to read all
> data at once. How can i suspend parsing for a time, read next chunk and
> continue?
>
> Thanks.
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 10
**


Beginners Digest, Vol 155, Issue 9

2021-06-24 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  A one- or two-page diagram of how Haskellworks?
  (Steven Leiva)
   2. Re:  A one- or two-page diagram of how Haskellworks?
  (Steven Leiva)
   3. Re:  A one- or two-page diagram of how Haskellworks?
  (Tarik ÖZKANLI)


--

Message: 1
Date: Thu, 24 Jun 2021 09:43:10 -0400
From: Steven Leiva 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] A one- or two-page diagram of how
Haskell works?
Message-ID:

Content-Type: text/plain; charset="utf-8"

Wonderful question. I would love to see something like this too.

What kind of confusion are you running into with Haskell? Are they of the
type error variety, or do you have a well-typed program that doesn't do
what you want?

*If* it is the type error stuff, I would recommend that you give the
compiler information about what you think the types are. The reason is that
type information can flow from very far away places than where you are
getting an error. For example, I was writing this code the other day:

*for eIdpData \ $(schoolId, districtId, tenantId) -> pure $ Right 1*

The type of for is *for :: (Traversable t, Applicative f) => t a -> (a -> f
b) -> f (t b)*

In my case, I knew the following:

*t ~ Either SyncFailure*
*a ~ IdpData*
*f ~ WriterT Logs m*
*b ~ Int*

Once I do replace type variables with concrete types / type constructors,
it becomes clear that my function argument should return an *Int* in some
structure, and instead I am returning an *Either a Int*. This helps me
figure out the problem.

Writing out takes a lot longer than actually doing it. Anyway, the key is
to provide GHC with the information you think you know; this will prevent
type inference from allowing type information to flow from far away places,
and the error will become clearer or at the very least more localized.

On Wed, Jun 23, 2021 at 11:42 PM Michael Turner <
michael.eugene.tur...@gmail.com> wrote:

> When I write C, or even C++, I have a mental model of how execution
> will proceed.
>
> When I write Prolog, but get confused, I run a kind of skeletal
> inference algorithm in my head and the confusion usually clears up. I
> can imagine how things are stored and what's done with them. I can see
> /through/ the code to the machine.
>
> With Haskell, I still feel blind.
>
> Has anyone summarized it all in a chart where I can look at it and
> think, "Ah, OK, GHC is taking this line and thinking of it THIS way"?
> If someone wanted to write an interpreter for Haskell, would there be
> a way for them to see how it would basically need to work, in one
> chart?
>
> Regards,
> Michael Turner
> Executive Director
> Project Persephone
> 1-25-33 Takadanobaba
> Shinjuku-ku Tokyo 169-0075
> Mobile: +81 (90) 5203-8682
> tur...@projectpersephone.org
>
> Understand - http://www.projectpersephone.org/
> Join - http://www.facebook.com/groups/ProjectPersephone/
> Donate - http://www.patreon.com/ProjectPersephone
> Volunteer - https://github.com/ProjectPersephone
>
> "Love does not consist in gazing at each other, but in looking outward
> together in the same direction." -- Antoine de Saint-Exupéry
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


-- 
Steven Leiva
305.528.6038
leiva.ste...@gmail.com
http://www.linkedin.com/in/stevenleiva
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Thu, 24 Jun 2021 09:45:27 -0400
From: Steven Leiva 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] A one- or two-page diagram of how
Haskell works?
Message-ID:

Content-Type: text/plain; charset="utf-8"

A few caveats to the above:

1) The literal *1* is polymorphic, but I hand-waved over that for now
2) *Either e Int* is an *Int* in *some* structure, but it's not the
structure we want. In the type signature for *for*, the function argument
does not contain the *t* type variable at all, which, again, is in our case *t
~ Either SyncFailure*.

On Thu, Jun 24, 2021 at 9:43 AM Steven Leiva  wrote:

> 

Beginners Digest, Vol 155, Issue 8

2021-06-24 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  A one- or two-page diagram of how Haskell works? (Michael Turner)


--

Message: 1
Date: Thu, 24 Jun 2021 12:41:58 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: [Haskell-beginners] A one- or two-page diagram of how Haskell
works?
Message-ID:

Content-Type: text/plain; charset="UTF-8"

When I write C, or even C++, I have a mental model of how execution
will proceed.

When I write Prolog, but get confused, I run a kind of skeletal
inference algorithm in my head and the confusion usually clears up. I
can imagine how things are stored and what's done with them. I can see
/through/ the code to the machine.

With Haskell, I still feel blind.

Has anyone summarized it all in a chart where I can look at it and
think, "Ah, OK, GHC is taking this line and thinking of it THIS way"?
If someone wanted to write an interpreter for Haskell, would there be
a way for them to see how it would basically need to work, in one
chart?

Regards,
Michael Turner
Executive Director
Project Persephone
1-25-33 Takadanobaba
Shinjuku-ku Tokyo 169-0075
Mobile: +81 (90) 5203-8682
tur...@projectpersephone.org

Understand - http://www.projectpersephone.org/
Join - http://www.facebook.com/groups/ProjectPersephone/
Donate - http://www.patreon.com/ProjectPersephone
Volunteer - https://github.com/ProjectPersephone

"Love does not consist in gazing at each other, but in looking outward
together in the same direction." -- Antoine de Saint-Exupéry


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 8
*


Beginners Digest, Vol 155, Issue 7

2021-06-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  DataKinds and GADTs question? (c...@coot.me)


--

Message: 1
Date: Sat, 12 Jun 2021 11:13:01 +
From: c...@coot.me
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] DataKinds and GADTs question?
Message-ID:



Content-Type: text/plain; charset="utf-8"

There isn't. GHC will infer kind `Type -> Type` for `MyType2`.  You can check 
that in `ghci` with `:kind MyType` and `:kind MyType2`.  There's also third way 
to write it by adding a standalone kind signature:
```
{-# LANGUAGE StandalondKindSignatures, GADTs #-}
type MyType3 :: Type -> Type
data MyType3 a where
  MkT3 :: Int -> MyType3 Int
```

A polykinded version would look like this:
```

{-# LANGUAGE PolyKinds #-}
type MyType4 :: forall a -> Type
data MyType4 a where
  MkT3 :: MyType4 Int

```

in `ghci` the kind of `MyType4` is:

```

:kind MyType4

MyType4 :: forall k. forall (a :: k) -> Type

```

Best regards,

Marcin

Sent with ProtonMail Secure Email.

‐‐‐ Original Message ‐‐‐

On Thursday, June 10th, 2021 at 13:15, Velichko Lefterov 
 wrote:

> I tried to understand DataKinds and GADTs...Is there a difference between:
> 

> data MyType :: Type -> Type where
> 

>   MyTypeConstructor :: Int -> MyType Int
> 

> data MyType2 a where
> 

>   MyTypeConstructor2 :: Int -> MyType2 Int
-- next part --
An HTML attachment was scrubbed...
URL: 

-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 509 bytes
Desc: OpenPGP digital signature
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 7
*


Beginners Digest, Vol 155, Issue 6

2021-06-10 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  DataKinds and GADTs question? (Velichko Lefterov)


--

Message: 1
Date: Thu, 10 Jun 2021 14:15:51 +0300
From: Velichko Lefterov 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] DataKinds and GADTs question?
Message-ID:

Content-Type: text/plain; charset="utf-8"

I tried to understand DataKinds and GADTs...
Is there a difference between:

data MyType :: Type -> Type where
  MyTypeConstructor :: Int -> MyType Int

data MyType2 a where
  MyTypeConstructor2 :: Int -> MyType2 Int
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 6
*


Beginners Digest, Vol 155, Issue 5

2021-06-07 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Designing TimeOut for Search Algorithm (Leonhard Applis)


--

Message: 1
Date: Mon, 07 Jun 2021 05:32:07 +
From: Leonhard Applis 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Designing TimeOut for Search Algorithm
Message-ID:



Content-Type: text/plain; charset="utf-8"

Good Morning, 

I currently want to write a search algorithm with 3 end conditions:
a) Solution Found 
b) N-iterations done 
c) x minutes timeout

I would like to split the function in two pieces, one which is pure with a seed 
and no timeout, and one time-outed in a monad (IO?).
So 
pureSearch :: Seed -> Iterations -> Maybe Result 
and 
search :: Timeout -> Seed -> Iterations -> IO Maybe Result

Is this a known Pattern? 
Do you know good examples for this behavior? 
Any other recommendations before I start implementing? 

Best
Leonhard
 
-- next part --
An HTML attachment was scrubbed...
URL: 

-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 509 bytes
Desc: OpenPGP digital signature
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 5
*


Beginners Digest, Vol 155, Issue 4

2021-06-06 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  import not working (Galaxy Being)
   2. Re:  import not working (Travis Cardwell)
   3.  Better intro to the All About Monads tutorial? (Michael Turner)


--

Message: 1
Date: Sat, 5 Jun 2021 17:23:32 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] import not working
Message-ID:

Content-Type: text/plain; charset="utf-8"

Let me reiterate, I'm not creating a stack project formally. I'm just going
to some directory at the command prompt and firing up ghci, which I presume
just uses the global installs. Then I'm creating .hs files in a text editor
and trying to load them at the REPL. How can I install stuff in this
instance?

On Fri, Jun 4, 2021 at 10:47 PM Galaxy Being  wrote:

> I run ghci with
>
> > stack ghci
>
>
>
> On Fri, Jun 4, 2021 at 5:19 PM Jesse Rudel  wrote:
>
>> How are you invoking ghci? If it's a stack project you can try stack ghci
>> if you haven't already.
>>
>> On Fri, 4 Jun 2021 at 21:51, Galaxy Being  wrote:
>>
>>> I go to a directory. I run
>>>
>>> stack install Safe
>>>
>>> I start up ghci and get the Prelude prompt. I run
>>>
>>> import Safe
>>>
>>> and I get
>>>
>>> import Safe
>>>   | ^^^
>>> Failed, no modules loaded.
>>>
>>> I'm once again frustrated. I try to load this hs file
>>>
>>> {-# LANGUAGE ViewPatterns #-}
>>> {-# LANGUAGE NoMonomorphismRestriction #-}
>>>
>>> import Safe
>>>
>>> lookupDefault :: Eq a => a -> b -> [(a,b)] -> b
>>> lookupDefault k _ (lookup k -> Just s) = s
>>> lookupDefault _ d _ = d
>>>
>>> headTup :: (a, [t]) -> [t]
>>> headTup (headMay . snd -> Just n) = [n]
>>> headTup _ = []
>>>
>>> headNil :: [a] -> [a]
>>> headNil (headMay -> Just x) = [x]
>>> headNil _ = []
>>>
>>> with the same result. What do I need to do?
>>> --
>>> ⨽
>>> Lawrence Bottorff
>>> Grand Marais, MN, USA
>>> borg...@gmail.com
>>> ___
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
> --
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
>


-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sun, 6 Jun 2021 09:32:25 +0900
From: Travis Cardwell 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] import not working
Message-ID:

Content-Type: text/plain; charset="UTF-8"

The `stack ghci` command does not load extra packages such as those
installed "globally."  This is a good thing, IMHO.  You can instruct
the command to load specific packages using the `--package` option.

Example:

stack repl --package safe

Example using your file:

stack repl --package safe GalaxyBeing.hs

Note that your email indicates usage of the `Safe` package (uppercase),
but that package is deprecated in favor of the `safe` package
(lowercase).  I mention it in case it is not intentional.

* 
* 

You may want to create a project that is just for testing.  You can then
specify which Stack snapshot to use in `stack.yaml` and which packages
to use in `package.yaml`.

stack new experiment

Travis


--

Message: 3
Date: Sun, 6 Jun 2021 10:50:08 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: [Haskell-beginners] Better intro to the All About Monads
tutorial?
Message-ID:

Content-Type: text/plain; charset="UTF-8"

I've done some work on this page:

https://wiki.haskell.org/All_About_Monads

I could use some help in improving my improvements

1. Beginners -- if you haven't looked at monads yet, does this new
intro boost your confidence?

2. Those who help beginners here -- have I committed any technical errors?

I was a little frustrated about the text as it stood. For example:

"... a monad is a way to 

Beginners Digest, Vol 155, Issue 2

2021-06-04 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Data constraint? (Francesco Ariis)
   2. Re:  Data constraint? (Galaxy Being)
   3.  import not working (Galaxy Being)
   4. Re:  import not working (Jesse Rudel)
   5. Re:  import not working (Galaxy Being)


--

Message: 1
Date: Fri, 4 Jun 2021 17:58:51 +0200
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Data constraint?
Message-ID: <20210604155851.GA29481@extensa>
Content-Type: text/plain; charset=utf-8

Il 03 giugno 2021 alle 17:40 Galaxy Being ha scritto:
> If I have a type
> 
> type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem
> 
> and I want to have the values of CaHardness and Alkalinity constrained to
> positive Int and between certain high and low values, I could do a newtype to
> creater a NaturalChem number, thus never less than 0, but what is the best
> practice to insure these values are between a certain range? Types in
> Haskell can't go that far, can they? Reading this

Mhhh you could create a smart constructor

data Prova = ProvConst Int  -- ProvConst does not get exported.

mkProva :: Int -> Prova -- This does get exported.
mkProva i | i > 100 = 100  -- or error "…
⁝

In a «Parse, don’t validate» [1] fashion.
If you need (as I suspect) to operate on those values, you will need
to define a few typeclasses (`numbers` [2] is a good example from
Hackage).
Would that do?
—F

[1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
[2] 
https://hackage.haskell.org/package/numbers-3000.2.0.2/docs/Data-Number-Natural.html


--

Message: 2
Date: Fri, 4 Jun 2021 11:13:33 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Data constraint?
Message-ID:

Content-Type: text/plain; charset="utf-8"

Yes, I just discovered the HaskellWiki article on smart constructors! Will
give it a try.

On Fri, Jun 4, 2021, 11:01 AM Francesco Ariis  wrote:

> Il 03 giugno 2021 alle 17:40 Galaxy Being ha scritto:
> > If I have a type
> >
> > type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem
> >
> > and I want to have the values of CaHardness and Alkalinity constrained to
> > positive Int and between certain high and low values, I could do a
> newtype to
> > creater a NaturalChem number, thus never less than 0, but what is the
> best
> > practice to insure these values are between a certain range? Types in
> > Haskell can't go that far, can they? Reading this
>
> Mhhh you could create a smart constructor
>
> data Prova = ProvConst Int  -- ProvConst does not get exported.
>
> mkProva :: Int -> Prova -- This does get exported.
> mkProva i | i > 100 = 100  -- or error "…
> ⁝
>
> In a «Parse, don’t validate» [1] fashion.
> If you need (as I suspect) to operate on those values, you will need
> to define a few typeclasses (`numbers` [2] is a good example from
> Hackage).
> Would that do?
> —F
>
> [1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
> [2]
> https://hackage.haskell.org/package/numbers-3000.2.0.2/docs/Data-Number-Natural.html
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Fri, 4 Jun 2021 16:48:11 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] import not working
Message-ID:

Content-Type: text/plain; charset="utf-8"

I go to a directory. I run

stack install Safe

I start up ghci and get the Prelude prompt. I run

import Safe

and I get

import Safe
  | ^^^
Failed, no modules loaded.

I'm once again frustrated. I try to load this hs file

{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

import Safe

lookupDefault :: Eq a => a -> b -> [(a,b)] -> b
lookupDefault k _ (lookup k -> Just s) = s
lookupDefault _ d _ = d

headTup :: (a, [t]) -> [t]
headTup (headMay . snd -> Just n) = [n]
headTup _ = []

headNil :: [a] -> [a]
headNil 

Beginners Digest, Vol 155, Issue 1

2021-06-04 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Data constraint? (Galaxy Being)


--

Message: 1
Date: Thu, 3 Jun 2021 17:40:41 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Data constraint?
Message-ID:

Content-Type: text/plain; charset="utf-8"

If I have a type

type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem

and I want to have the values of CaHardness and Alkalinity constrained to
positive Int and between certain high and low values, I could do a newtype to
creater a NaturalChem number, thus never less than 0, but what is the best
practice to insure these values are between a certain range? Types in
Haskell can't go that far, can they? Reading this
 tells me I can have some
of what I want. How are type values that need to be constrained handled
best practices? Again, the type world of Haskell seems to do some of the
lifting, but I'd like some advice if I want to have both of my constraints.




-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 155, Issue 1
*


Beginners Digest, Vol 154, Issue 13

2021-05-28 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  How to show the help page of a function (Francesco Ariis)


--

Message: 1
Date: Thu, 27 May 2021 17:40:24 +0200
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to show the help page of a
function
Message-ID: <20210527154024.GB27422@extensa>
Content-Type: text/plain; charset=utf-8

Il 26 maggio 2021 alle 18:53 Peng Yu ha scritto:
> $ ghci
> GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help
> Prelude> :doc many
> 
> :1:1: error: Not in scope: ‘many’
> 
> Any way to automatically determine the module to load and load it
> automatically in the command line?

You might do this by installing Hoogle locally [1]

[1] https://github.com/ndmitchell/hoogle/blob/master/docs/Install.md


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 13
**


Beginners Digest, Vol 154, Issue 12

2021-05-27 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  How to show the help page of a function (Peng Yu)
   2. Re:  How to show the help page of a function (Francesco Ariis)
   3. Re:  How to show the help page of a function (Peng Yu)


--

Message: 1
Date: Wed, 26 May 2021 18:22:15 -0500
From: Peng Yu 
To: beginners@haskell.org
Subject: [Haskell-beginners] How to show the help page of a function
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Hi,

I want to check the help page of a function in haskell. For example,
to check the help page of "many", could anybody help me know to get to
its help page? Thanks.

-- 
Regards,
Peng


--

Message: 2
Date: Thu, 27 May 2021 01:27:06 +0200
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to show the help page of a
function
Message-ID: <20210526232706.GA24795@extensa>
Content-Type: text/plain; charset=utf-8

Hello Peng,

Il 26 maggio 2021 alle 18:22 Peng Yu ha scritto:
> I want to check the help page of a function in haskell. For example,
> to check the help page of "many", could anybody help me know to get to
> its help page? Thanks.

A quick way to do it is :doc inside ghci, like

λ> :doc head
 /O(1)/. Extract the first element of a list, which must be non-empty.

If you prefer something in your web-browser, hoogle can help you

https://hoogle.haskell.org/?hoogle=many=set%3Astackage

Does this help?
—F



--

Message: 3
Date: Wed, 26 May 2021 18:53:06 -0500
From: Peng Yu 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] How to show the help page of a
function
Message-ID:

Content-Type: text/plain; charset="UTF-8"

$ ghci
GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help
Prelude> :doc many

:1:1: error: Not in scope: ‘many’

Any way to automatically determine the module to load and load it
automatically in the command line?

On 5/26/21, Francesco Ariis  wrote:
> Hello Peng,
>
> Il 26 maggio 2021 alle 18:22 Peng Yu ha scritto:
>> I want to check the help page of a function in haskell. For example,
>> to check the help page of "many", could anybody help me know to get to
>> its help page? Thanks.
>
> A quick way to do it is :doc inside ghci, like
>
> λ> :doc head
>  /O(1)/. Extract the first element of a list, which must be non-empty.
>
> If you prefer something in your web-browser, hoogle can help you
>
> https://hoogle.haskell.org/?hoogle=many=set%3Astackage
>
> Does this help?
> —F
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


-- 
Regards,
Peng


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 12
**


Beginners Digest, Vol 154, Issue 11

2021-05-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  (Online) Utrecht Summer School on Advanced functional
  programming (Andrei Dziahel)


--

Message: 1
Date: Tue, 25 May 2021 18:13:04 +0200
From: Andrei Dziahel 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Cc: "hask...@haskell.org" ,
"haskell-c...@haskell.org" 
Subject: Re: [Haskell-beginners] (Online) Utrecht Summer School on
Advanced functional programming
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Exciting initiative, looking forward to attend it.

The afp.school site doesn't seem to mention the link to the course
page itself which you'll need along the course of the application, so
here it goes for everyone's convenience —
https://www.utrechtsummerschool.nl/courses/science/applied-functional-programming-in-haskell


On Thu, May 6, 2021 at 5:14 PM Swierstra, W.S. (Wouter)
 wrote:
>
> SUMMER SCHOOL ON ADVANCED FUNCTIONAL PROGRAMMING
>
> Online -  05-9 July 2021
>
>  http://www.afp.school
>
> # Call for Participation
>
> ## About
>
> The Advanced Functional Programming summer school has been running for
> more than ten years. We aim to educate aspiring Haskell programmers
> beyond the basic material covered by many textbooks.
>
> This year the course will be offered *online only*. A typical day will
> consist a 2-3 hours of lectures, sandwiched between supervised lab
> sessions. Lectures will be held in the (European) afternoon, but
> recordings will be made available if attending live is problematic.
>
> The lectures will cover several more advanced topics regarding
> programming with types in Haskell, including topics such as:
>
>* monads and applicative functors;
>* lambda calculus;
>* generalized algebraic datatypes;
>* datatype generic programming
>* type families and type-level programming;
>
> ## Lecturers
>
> Utrecht staff:
> * Gabriele Keller
> * Trevor McDonell
> * Wouter Swierstra
>
> ## Prerequisites
>
> We expect students to have a basic familiarity with Haskell
> already. You should be able to write recursive functions over
> algebraic data types, such as lists and trees. There is a great deal
> of material readily available that covers this material. If you've
> already started learning Haskell and are looking to take your
> functional programming skills to the next level, this is the course
> for you.
>
> Soft registration deadline: 1 June, 2021
> School: 05-09 July, 2021
>
> ## Costs
>
>50 euro - Registration fee
>
> We ask ask participants to pay a small registration fee to cover some
> of our organizational expenses. If this is problematic for you *for
> whatever reason*, please let us know and we can waive your
> registration fee.
>
> ## Further information
>
> Further information, including instructions on how to register, is
> available on our website:
>
>http://www.afp.school
>
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



-- 
Regards,
Andrei Dziahel


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 11
**


Beginners Digest, Vol 154, Issue 10

2021-05-22 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Beginners Digest, Vol 154, Issue 9 (Michael Turner)


--

Message: 1
Date: Sat, 22 May 2021 18:57:49 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 154, Issue 9
Message-ID:

Content-Type: text/plain; charset="UTF-8"

That did work, thank you. I wish instructions in the wiki included examples.

A lot of my struggles as a newbie are with

(1) cabal+stack, trying to conform to ways of doing things to get
effects (e.g., perfect reproducibility) I don't even care about right
now, and

(2) documentation that doesn't tell you much about how to make things work.

Regards,
Michael Turner
Executive Director
Project Persephone
1-25-33 Takadanobaba
Shinjuku-ku Tokyo 169-0075
Mobile: +81 (90) 5203-8682
tur...@projectpersephone.org

Understand - http://www.projectpersephone.org/
Join - http://www.facebook.com/groups/ProjectPersephone/
Donate - http://www.patreon.com/ProjectPersephone
Volunteer - https://github.com/ProjectPersephone

"Love does not consist in gazing at each other, but in looking outward
together in the same direction." -- Antoine de Saint-Exupéry

On Thu, May 20, 2021 at 9:08 PM  wrote:
>
> Send Beginners mailing list submissions to
> beginners@haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
> beginners-requ...@haskell.org
>
> You can reach the person managing the list at
> beginners-ow...@haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>1.  Getting debugging going in ghci -- is there no   mercy?
>   (Michael Turner)
>2. Re:  Getting debugging going in ghci -- is there no mercy?
>   (Francesco Ariis)
>
>
> --
>
> Message: 1
> Date: Wed, 19 May 2021 21:10:50 +0900
> From: Michael Turner 
> To: beginners@haskell.org
> Subject: [Haskell-beginners] Getting debugging going in ghci -- is
> there nomercy?
> Message-ID:
> 
> Content-Type: text/plain; charset="UTF-8"
>
> According to the Haskell wiki, "The trace function is located in the
> base package", which encouraged me to think it should just work by
> starting ghci. No such luck. So then I tried "stack gchi --package
> debug". No such luck. I added packages to stack.yaml as suggested. And
> here's where I am now.
>
> Of course, I'd like cookbook instructions, but I'm also including all
> this error output to give people an idea of how incredibly
> demoralizing the experience of being a newbie can be. As a newbie,
> it's easy to get confused about what Haskell is actually doing. So
> you'd naturally like a way to inspect intermediate results. Which
> means you'd like tracing and debugging.
>
> Why is it so hard to get there?
>
> ---
>
>
> C:\Users\Michael Turner\aug\aug.cabal was modified manually. Ignoring
> C:\Users\Michael Turner\aug\package.yaml in favor of the cabal file.
> If you want to use the package.yaml file instead of the cabal file,
> then please delete the cabal file.
>
> Using main module: 1. Package `aug' component aug:exe:aug-exe with
> main-is file: C:\Users\Michael Turner\aug\app\Main.hs
> WARNING: Ignoring transformers-compat's bounds on transformers (>=0.3
> && ==0.2.*); using transformers-0.5.6.2.
> Reason: allow-newer enabled.
>
> Error: While constructing the build plan, the following exceptions were
> encountered:
>
> In the dependencies for Hoed-0.5.1:
> QuickCheck needed, but the stack configuration has no specified version
>(latest matching version is 2.14.2)
> cereal needed, but the stack configuration has no specified version  
> (latest
>matching version is 0.5.8.1)
> cereal-text needed, but the stack configuration has no specified version
> (latest matching version is 0.1.0.2)
> cereal-vector needed, but the stack configuration has no specified version
>   (latest matching version is 0.2.0.1)
> primitive needed, but the stack configuration has no specified version
>   (latest matching version is 0.7.1.0)
> regex-tdfa needed, but the stack configuration has no specified version
>  

Beginners Digest, Vol 154, Issue 9

2021-05-20 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Getting debugging going in ghci -- is there no   mercy?
  (Michael Turner)
   2. Re:  Getting debugging going in ghci -- is there no mercy?
  (Francesco Ariis)


--

Message: 1
Date: Wed, 19 May 2021 21:10:50 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: [Haskell-beginners] Getting debugging going in ghci -- is
there nomercy?
Message-ID:

Content-Type: text/plain; charset="UTF-8"

According to the Haskell wiki, "The trace function is located in the
base package", which encouraged me to think it should just work by
starting ghci. No such luck. So then I tried "stack gchi --package
debug". No such luck. I added packages to stack.yaml as suggested. And
here's where I am now.

Of course, I'd like cookbook instructions, but I'm also including all
this error output to give people an idea of how incredibly
demoralizing the experience of being a newbie can be. As a newbie,
it's easy to get confused about what Haskell is actually doing. So
you'd naturally like a way to inspect intermediate results. Which
means you'd like tracing and debugging.

Why is it so hard to get there?

---


C:\Users\Michael Turner\aug\aug.cabal was modified manually. Ignoring
C:\Users\Michael Turner\aug\package.yaml in favor of the cabal file.
If you want to use the package.yaml file instead of the cabal file,
then please delete the cabal file.

Using main module: 1. Package `aug' component aug:exe:aug-exe with
main-is file: C:\Users\Michael Turner\aug\app\Main.hs
WARNING: Ignoring transformers-compat's bounds on transformers (>=0.3
&& ==0.2.*); using transformers-0.5.6.2.
Reason: allow-newer enabled.

Error: While constructing the build plan, the following exceptions were
encountered:

In the dependencies for Hoed-0.5.1:
QuickCheck needed, but the stack configuration has no specified version
   (latest matching version is 2.14.2)
cereal needed, but the stack configuration has no specified version  (latest
   matching version is 0.5.8.1)
cereal-text needed, but the stack configuration has no specified version
(latest matching version is 0.1.0.2)
cereal-vector needed, but the stack configuration has no specified version
  (latest matching version is 0.2.0.1)
primitive needed, but the stack configuration has no specified version
  (latest matching version is 0.7.1.0)
regex-tdfa needed, but the stack configuration has no specified version
   (latest matching version is 1.3.1.0)
regex-tdfa-text needed, but the stack configuration has no specified version
(latest matching version is 1.0.0.3)
semigroups needed, but the stack configuration has no specified version
   (latest matching version is 0.19.1)
strict needed, but the stack configuration has no specified version  (latest
   matching version is 0.4.0.1)
terminal-size needed, but the stack configuration has no specified version
  (latest matching version is 0.3.2.1)
vector-th-unbox needed, but the stack configuration has no specified version
(latest matching version is 0.2.1.9)
needed due to debug-0.1.1 -> Hoed-0.5.1

In the dependencies for aeson-1.5.6.0:
attoparsec must match >=0.13.2.2 && <0.15, but the stack
configuration has no
   specified version  (latest matching version is 0.14.1)
base-compat-batteries must match >=0.10.0 && <0.12, but the stack
  configuration has no specified version
(latest matching
  version is 0.11.2)
data-fix must match >=0.3 && <0.4, but the stack configuration has no
 specified version  (latest matching version is 0.3.1)
dlist must match >=0.8.0.4 && <1.1, but the stack configuration has no
  specified version  (latest matching version is 1.0)
primitive must match >=0.7.0.1 && <0.8, but the stack configuration has no
  specified version  (latest matching version is 0.7.1.0)
scientific must match >=0.3.6.2 && <0.4, but the stack configuration has no
   specified version  (latest matching version is 0.3.6.2)
strict must match >=0.4 && <0.5, but the stack configuration has
no specified
   version  (latest matching version is 0.4.0.1)
tagged must match >=0.8.6 && <0.9, but the stack configuration 

Beginners Digest, Vol 154, Issue 8

2021-05-19 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Beginners Digest, Vol 154, Issue 7 (Michael Turner)


--

Message: 1
Date: Wed, 19 May 2021 20:21:06 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 154, Issue 7
Message-ID:

Content-Type: text/plain; charset="UTF-8"

Ah, thank you. I just went with the more up-to-date version of the
code, and didn't look at the original.

Regards,
Michael Turner
Executive Director
Project Persephone
1-25-33 Takadanobaba
Shinjuku-ku Tokyo 169-0075
Mobile: +81 (90) 5203-8682
tur...@projectpersephone.org

Understand - http://www.projectpersephone.org/
Join - http://www.facebook.com/groups/ProjectPersephone/
Donate - http://www.patreon.com/ProjectPersephone
Volunteer - https://github.com/ProjectPersephone

"Love does not consist in gazing at each other, but in looking outward
together in the same direction." -- Antoine de Saint-Exupéry

On Tue, May 18, 2021 at 9:06 PM  wrote:
>
> Send Beginners mailing list submissions to
> beginners@haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
> beginners-requ...@haskell.org
>
> You can reach the person managing the list at
> beginners-ow...@haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>1.  Type inference or just ... a typo in a paper? (Michael Turner)
>2. Re:  Type inference or just ... a typo in a   paper?
>   (Francesco Ariis)
>
>
> --
>
> Message: 1
> Date: Tue, 18 May 2021 17:24:37 +0900
> From: Michael Turner 
> To: beginners@haskell.org
> Subject: [Haskell-beginners] Type inference or just ... a typo in a
> paper?
> Message-ID:
> 
> Content-Type: text/plain; charset="UTF-8"
>
> I've inherited some Haskell code, which you can find here:
>
> http://web.cecs.pdx.edu/~mpj/pubs/aug.html
>
> The text of the accompanying paper says, "we extend the Text class..."
> -- but the identifier "Text" appears nowhere in the code. Is this just
> an error in the paper, or is the Text class getting involved in some
> indirect way, e.g. through String or perhaps because of the line
> "instance Show Tree where . . ."?
>
>
> Regards,
> Michael Turner
> Executive Director
> Project Persephone
> 1-25-33 Takadanobaba
> Shinjuku-ku Tokyo 169-0075
> Mobile: +81 (90) 5203-8682
> tur...@projectpersephone.org
>
> Understand - http://www.projectpersephone.org/
> Join - http://www.facebook.com/groups/ProjectPersephone/
> Donate - http://www.patreon.com/ProjectPersephone
> Volunteer - https://github.com/ProjectPersephone
>
> "Love does not consist in gazing at each other, but in looking outward
> together in the same direction." -- Antoine de Saint-Exupéry
>
>
> --
>
> Message: 2
> Date: Tue, 18 May 2021 13:30:58 +0200
> From: Francesco Ariis 
> To: beginners@haskell.org
> Subject: Re: [Haskell-beginners] Type inference or just ... a typo in
> a   paper?
> Message-ID: <20210518113058.GB879@extensa>
> Content-Type: text/plain; charset=utf-8
>
> Hello Michael,
>
> Il 18 maggio 2021 alle 17:24 Michael Turner ha scritto:
> > I've inherited some Haskell code, which you can find here:
> >
> > http://web.cecs.pdx.edu/~mpj/pubs/aug.html
> >
> > The text of the accompanying paper says, "we extend the Text class..."
> > -- but the identifier "Text" appears nowhere in the code. Is this just
> > an error in the paper, or is the Text class getting involved in some
> > indirect way, e.g. through String or perhaps because of the line
> > "instance Show Tree where . . ."?
>
> In the updated source (`augupdated.hs`) that is missing, but in the
> /original/ one (`aug.hs`) I read at line 255
>
> instance Text Tree where
>
> Which was then replaced with:
>
> instance Show Tree where
>
> in the updated version.
>
> Weird to know something like `Show` was not named like that in the early
> nineties!
> —F
>
>
> --
>
> Subject: Digest Footer
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> 

Beginners Digest, Vol 154, Issue 7

2021-05-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Type inference or just ... a typo in a paper? (Michael Turner)
   2. Re:  Type inference or just ... a typo in a   paper?
  (Francesco Ariis)


--

Message: 1
Date: Tue, 18 May 2021 17:24:37 +0900
From: Michael Turner 
To: beginners@haskell.org
Subject: [Haskell-beginners] Type inference or just ... a typo in a
paper?
Message-ID:

Content-Type: text/plain; charset="UTF-8"

I've inherited some Haskell code, which you can find here:

http://web.cecs.pdx.edu/~mpj/pubs/aug.html

The text of the accompanying paper says, "we extend the Text class..."
-- but the identifier "Text" appears nowhere in the code. Is this just
an error in the paper, or is the Text class getting involved in some
indirect way, e.g. through String or perhaps because of the line
"instance Show Tree where . . ."?


Regards,
Michael Turner
Executive Director
Project Persephone
1-25-33 Takadanobaba
Shinjuku-ku Tokyo 169-0075
Mobile: +81 (90) 5203-8682
tur...@projectpersephone.org

Understand - http://www.projectpersephone.org/
Join - http://www.facebook.com/groups/ProjectPersephone/
Donate - http://www.patreon.com/ProjectPersephone
Volunteer - https://github.com/ProjectPersephone

"Love does not consist in gazing at each other, but in looking outward
together in the same direction." -- Antoine de Saint-Exupéry


--

Message: 2
Date: Tue, 18 May 2021 13:30:58 +0200
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type inference or just ... a typo in
a   paper?
Message-ID: <20210518113058.GB879@extensa>
Content-Type: text/plain; charset=utf-8

Hello Michael,

Il 18 maggio 2021 alle 17:24 Michael Turner ha scritto:
> I've inherited some Haskell code, which you can find here:
> 
> http://web.cecs.pdx.edu/~mpj/pubs/aug.html
> 
> The text of the accompanying paper says, "we extend the Text class..."
> -- but the identifier "Text" appears nowhere in the code. Is this just
> an error in the paper, or is the Text class getting involved in some
> indirect way, e.g. through String or perhaps because of the line
> "instance Show Tree where . . ."?

In the updated source (`augupdated.hs`) that is missing, but in the
/original/ one (`aug.hs`) I read at line 255

instance Text Tree where

Which was then replaced with:

instance Show Tree where

in the updated version.

Weird to know something like `Show` was not named like that in the early
nineties!
—F


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 7
*


Beginners Digest, Vol 154, Issue 6

2021-05-14 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Function to compute the mean (c...@coot.me)


--

Message: 1
Date: Fri, 14 May 2021 07:43:08 +
From: c...@coot.me
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:



Content-Type: text/plain; charset="utf-8"

If you want a much more performant solution, go around the list once. Another 
advantage is that it will run in constant memory.

```

-- requires BangPatterns extension; bonus questions:

-- * Can you predict what will happen with out bang patterns?

-- * Would `foldl'` work even without any bang patterns?
mean5 :: [Double] -> Double
mean5 = snd . foldl (\(!n, !r) a -> (n + 1, a / n + (n - 1) / n * r)) (1, 0)

```

`mean5` on my system reports:
```
   1,840,101,632 bytes allocated in the heap
 197,896 bytes copied during GC
  44,408 bytes maximum residency (2 sample(s))
  29,320 bytes maximum slop
   2 MiB total memory in use (0 MB lost due to fragmentation)

 Tot time (elapsed)  Avg pause  Max pause
  Gen  0  1774 colls, 0 par    0.005s   0.006s 0.s    0.s
  Gen  1 2 colls, 0 par    0.000s   0.000s 0.0001s    0.0001s

  INIT    time    0.000s  (  0.000s elapsed)
  MUT time    0.236s  (  0.235s elapsed)
  GC  time    0.005s  (  0.006s elapsed)
  EXIT    time    0.000s  (  0.000s elapsed)
  Total   time    0.241s  (  0.241s elapsed)

  %GC time   0.0%  (0.0% elapsed)

  Alloc rate    7,803,840,935 bytes per MUT second

  Productivity  97.9% of total user, 97.5% of total elapsed

```

while `mean`
```
   1,280,101,688 bytes allocated in the heap
   1,099,489,280 bytes copied during GC
 294,937,752 bytes maximum residency (12 sample(s))
  50,518,888 bytes maximum slop
 670 MiB total memory in use (0 MB lost due to fragmentation)

 Tot time (elapsed)  Avg pause  Max pause
  Gen  0  1209 colls, 0 par    0.379s   0.381s 0.0003s    0.0012s
  Gen  1    12 colls, 0 par    0.976s   0.976s 0.0813s    0.3921s

  INIT    time    0.000s  (  0.000s elapsed)
  MUT time    0.324s  (  0.322s elapsed)
  GC  time    1.355s  (  1.357s elapsed)
  EXIT    time    0.000s  (  0.000s elapsed)
  Total   time    1.679s  (  1.679s elapsed)

  %GC time   0.0%  (0.0% elapsed)

  Alloc rate    3,956,490,811 bytes per MUT second

  Productivity  19.3% of total user, 19.2% of total elapsed

```

I  compiled both with `ghc -O2 -rtsopts` and run them with `./Mean +RTS -s` 
(one does not nead to link the profiled RTS for `-s` to work).

Cheers,

Marcin

Sent with ProtonMail Secure Email.

‐‐‐ Original Message ‐‐‐

On Monday, May 10th, 2021 at 14:23, David James  wrote:

> Ugh – sent too soon!
> 

> Hello – I wanted to add some comments. mean is as you describe.
> 

> mean1 as defined can take a list of any Real type, and return any Fractional 
> type. These types need not be the same, and it’s up to the *caller* of mean1 
> to say what types they want to give and get returned, e.g. the following is 
> possible:
> 

> > :m +Data.Ratio
> 

> > :m +Data.Complex
> 

> > mean1 [6%5, 2%3] :: Complex Double
> 

> 0.9333 :+ 0.0
> 

> This may not be what you were expecting? There’s also no need to restrict to 
> Real, since it is valid to calculate the mean of a list of e.g. complex 
> numbers. So maybe you want something like this:
> 

> mean2 :: (Fractional a) => [a] -> a
> 

> mean2 xs = sum xs / genericLength xs
> 

> (the realToFrac is now unnecessary). The caller still decides the type, but 
> the argument and result type now have to be the same.
> 

> You can’t now do mean2 foo, but you can do mean2 [1,2,3] (and the 1, 2, 3 are 
> interpreted as the default fractional type, probably Double).
> 

> I personally prefer to write “utility” functions to be as generic as 
> possible. (Imagine you’re including them in some standard library for the 
> whole world to use). But I’m sure there are other opinions.
> 

> Re performance, there is a comment against “genericLength” to say that it is 
> not as efficient as length. And, as used above, this is the case. So maybe 
> you actually want:
> 

> mean3 :: (Fractional a) => [a] -> a
> 

> mean3 xs = sum xs / fromIntegral 

Beginners Digest, Vol 154, Issue 5

2021-05-11 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Function to compute the mean (David James)


--

Message: 1
Date: Mon, 10 May 2021 12:23:59 +
From: David James 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:



Content-Type: text/plain; charset="windows-1252"

Ugh – sent too soon!

Hello – I wanted to add some comments. mean is as you describe.

mean1 as defined can take a list of any Real type, and return any Fractional 
type. These types need not be the same, and it’s up to the *caller* of mean1 to 
say what types they want to give and get returned, e.g. the following is 
possible:

> :m +Data.Ratio
> :m +Data.Complex
> mean1 [6%5, 2%3] :: Complex Double
0.9333 :+ 0.0

This may not be what you were expecting? There’s also no need to restrict to 
Real, since it is valid to calculate the mean of a list of e.g. complex 
numbers. So maybe you want something like this:

mean2 :: (Fractional a) => [a] -> a
mean2 xs = sum xs / genericLength xs

(the realToFrac is now unnecessary). The caller still decides the type, but the 
argument and result type now have to be the same.

You can’t now do mean2 foo, but you can do mean2 [1,2,3] (and the 1, 2, 3 are 
interpreted as the default fractional type, probably Double).

I personally prefer to write “utility” functions to be as generic as possible. 
(Imagine you’re including them in some standard library for the whole world to 
use). But I’m sure there are other opinions.

Re performance, there is a comment against “genericLength” to say that it is 
not as efficient as length. And, as used above, this is the case. So maybe you 
actually want:

mean3 :: (Fractional a) => [a] -> a
mean3 xs = sum xs / fromIntegral (length xs)

which is as efficient as mean.

If you are especially interested in performance, you might want to read 
this. 
It’s not really “beginner level” but does look at some issues with mean in some 
detail (and in particular why it can use so much memory and what you can do 
about that). Performance of Haskell code is often more difficult to predict 
than for other languages, for example due to lazy evaluation and some amazing 
transformations of you code done by GHC.

Incidentally, I am in the middle of drafting a page about 
numbers to include in the 
Haskell wikibook that might be interesting. It discusses types, classes, 
defaults numeric conversions, etc. I would be very happy if for any feedback 
(please leave any on the “Discussion” tab on the page).

FYI: I tested performance (on GHC 8.4.3 on Windows) with this:

{-
compile: ghc -O2 -prof -fprof-auto -rtsopts Mean.hs
run: Mean +RTS -p > nul
-}

module Main (main) where

import Data.List

mean :: [Double] -> Double
mean xs = sum xs / fromIntegral (length xs)

mean1 :: (Real a, Fractional b) => [a] -> b
mean1 xs = realToFrac (sum xs) / genericLength xs

mean2 :: (Fractional a) => [a] -> a
mean2 xs = sum xs / genericLength xs

mean3 :: (Fractional a) => [a] -> a
mean3 xs = sum xs / fromIntegral (length xs)

mean4 :: (Fractional a) => [a] -> a
mean4 xs = sum xs / fromIntegral (genericLength xs :: Int)

main :: IO ()
main = do
  let xs = [1 .. 1000] :: [Double] --may default to Integer unless 
specified as Double.
  print $ mean xs  --change to mean1, etc, for different 
runs

And got:


Total time
Total alloc
mean
0.10
1,680,096,640 bytes
mean1
0.17
2,560,096,656 bytes
mean2
0.17
2,560,096,656 bytes
mean3
0.10
1,680,096,640 bytes
mean4
0.10
1,680,096,640 bytes

mean4 also uses genericLength but is as fast as length. This is due to some 
cleaverness in GHC, where it uses more efficient code when it knows the 
required result is integral.



From: Beginners  on behalf of Joe King 

Sent: Saturday, May 8, 2021 10:39:50 AM
To: beginners@haskell.org 
Subject: [Haskell-beginners] Function to compute the mean

Greeetings I am new here and pretty new to Haskell.

I was wondering what are the relative advanatges/disadvatnages of specifying a 
mean function in these two ways:

mean :: [Double] -> Double
mean xs = sum xs / fromIntegral (length xs)

and

mean1 :: (Real a, Fractional b) => [a] -> b
mean1 xs = realToFrac (sum xs) / genericLength xs

I understand 

Beginners Digest, Vol 154, Issue 4

2021-05-10 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Function to compute the mean (David James)


--

Message: 1
Date: Mon, 10 May 2021 11:43:03 +
From: David James 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:



Content-Type: text/plain; charset="windows-1252"

Hello – I wanted to add some comments. mean is as you describe.

mean1 as defined can take a list of any Real type, and return any Fractional 
type. These types need not be the same, and it’s up to the *caller* of mean1 to 
say what types they want to give and get returned, e.g. the following is 
possible:

> :m +Data.Ratio
> :m +Data.Complex
> mean1 [6%5, 2%3] :: Complex Double
0.9333 :+ 0.0

This may not be what you were expecting, and maybe you want something like this:

mean2 :: (Fractional a) => [a] -> a
mean2 xs = sum xs / genericLength xs

(and note the realToFrac is then unces




From: Beginners  on behalf of Joe King 

Sent: Saturday, May 8, 2021 10:39:50 AM
To: beginners@haskell.org 
Subject: [Haskell-beginners] Function to compute the mean

Greeetings I am new here and pretty new to Haskell.

I was wondering what are the relative advanatges/disadvatnages of specifying a 
mean function in these two ways:

mean :: [Double] -> Double
mean xs = sum xs / fromIntegral (length xs)

and

mean1 :: (Real a, Fractional b) => [a] -> b
mean1 xs = realToFrac (sum xs) / genericLength xs

I understand that mean1 has the advantage that it can be called with lists of 
any Real type, so would work with things like

foo :: [Int]
foo = [1,2,3]

mean foo
-- type mismatch error

mean1 foo
-- no error

But suppose that I know I will only ever use lists of Double, is there still 
any advantage (or disadvantage of using mean1). For example is there any 
performance benefit by using mean in that case since mean1 has additional 
function evaluation.

Are there any other considerations ?

Thanks in advance
JK
___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- next part --
An HTML attachment was scrubbed...
URL: 

-- next part --
A non-text attachment was scrubbed...
Name: C41BD4BD0CBD4F519B49D2A93C03CE4A.png
Type: image/png
Size: 144 bytes
Desc: C41BD4BD0CBD4F519B49D2A93C03CE4A.png
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 4
*


Beginners Digest, Vol 154, Issue 3

2021-05-09 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Function to compute the mean (Tarik ÖZKANLI)
   2. Re:  Function to compute the mean (Tarik ÖZKANLI)
   3. Re:  Function to compute the mean (Joe King)
   4. Re:  Function to compute the mean (Tarik ÖZKANLI)


--

Message: 1
Date: Sat, 8 May 2021 16:07:46 +0300
From: Tarik ÖZKANLI 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

In standard usage there is not much difference. But in Haskell, people
prefer to write in curried form (first implementation of yours) which has
the advantage of using partially applied form when suitable.

Regards.

Tarık Özkanlı


On Sat, 8 May 2021 at 12:43, Joe King  wrote:

> Greeetings I am new here and pretty new to Haskell.
>
> I was wondering what are the relative advanatges/disadvatnages of
> specifying a mean function in these two ways:
>
> mean :: [Double] -> Double
> mean xs = sum xs / fromIntegral (length xs)
>
> and
>
> mean1 :: (Real a, Fractional b) => [a] -> b
> mean1 xs = realToFrac (sum xs) / genericLength xs
>
> I understand that mean1 has the advantage that it can be called with lists
> of any Real type, so would work with things like
>
> foo :: [Int]
> foo = [1,2,3]
>
> mean foo
> -- type mismatch error
>
> mean1 foo
> -- no error
>
> But suppose that I know I will only ever use lists of Double, is there
> still any advantage (or disadvantage of using mean1). For example is there
> any performance benefit by using mean in that case since mean1 has
> additional function evaluation.
>
> Are there any other considerations ?
>
> Thanks in advance
> JK
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sat, 8 May 2021 16:11:03 +0300
From: Tarik ÖZKANLI 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:

Content-Type: text/plain; charset="utf-8"

No sorry,

Both are the same,
Discard my previous mail

Regards.

Tarık

On Sat, 8 May 2021 at 16:07, Tarik ÖZKANLI  wrote:

> Hello,
>
> In standard usage there is not much difference. But in Haskell, people
> prefer to write in curried form (first implementation of yours) which has
> the advantage of using partially applied form when suitable.
>
> Regards.
>
> Tarık Özkanlı
>
>
> On Sat, 8 May 2021 at 12:43, Joe King  wrote:
>
>> Greeetings I am new here and pretty new to Haskell.
>>
>> I was wondering what are the relative advanatges/disadvatnages of
>> specifying a mean function in these two ways:
>>
>> mean :: [Double] -> Double
>> mean xs = sum xs / fromIntegral (length xs)
>>
>> and
>>
>> mean1 :: (Real a, Fractional b) => [a] -> b
>> mean1 xs = realToFrac (sum xs) / genericLength xs
>>
>> I understand that mean1 has the advantage that it can be called with
>> lists of any Real type, so would work with things like
>>
>> foo :: [Int]
>> foo = [1,2,3]
>>
>> mean foo
>> -- type mismatch error
>>
>> mean1 foo
>> -- no error
>>
>> But suppose that I know I will only ever use lists of Double, is there
>> still any advantage (or disadvantage of using mean1). For example is there
>> any performance benefit by using mean in that case since mean1 has
>> additional function evaluation.
>>
>> Are there any other considerations ?
>>
>> Thanks in advance
>> JK
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Sat, 8 May 2021 19:33:33 + (UTC)
From: Joe King 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Function to compute the mean

Beginners Digest, Vol 154, Issue 2

2021-05-08 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Function to compute the mean (Joe King)


--

Message: 1
Date: Sat, 8 May 2021 09:39:50 + (UTC)
From: Joe King 
To: "beginners@haskell.org" 
Subject: [Haskell-beginners] Function to compute the mean
Message-ID: <1095405637.961440.1620466790...@mail.yahoo.com>
Content-Type: text/plain; charset=UTF-8

Greeetings I am new here and pretty new to Haskell.

I was wondering what are the relative advanatges/disadvatnages of specifying a 
mean function in these two ways:

mean :: [Double] -> Double
mean xs = sum xs / fromIntegral (length xs)

and

mean1 :: (Real a, Fractional b) => [a] -> b
mean1 xs = realToFrac (sum xs) / genericLength xs

I understand that mean1 has the advantage that it can be called with lists of 
any Real type, so would work with things like 

foo :: [Int]
foo = [1,2,3]

mean foo
-- type mismatch error

mean1 foo
-- no error

But suppose that I know I will only ever use lists of Double, is there still 
any advantage (or disadvantage of using mean1). For example is there any 
performance benefit by using mean in that case since mean1 has additional 
function evaluation. 

Are there any other considerations ?

Thanks in advance
JK


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 2
*


Beginners Digest, Vol 154, Issue 1

2021-05-07 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  (Online) Utrecht Summer School on Advanced   functional
  programming (Swierstra, W.S. (Wouter))


--

Message: 1
Date: Thu, 6 May 2021 15:05:07 +
From: "Swierstra, W.S. (Wouter)" 
To: "beginners@haskell.org" ,
"hask...@haskell.org" ,
"haskell-c...@haskell.org" 
Subject: [Haskell-beginners] (Online) Utrecht Summer School on
Advancedfunctional programming
Message-ID: <959d805c-b436-7357-4ba7-893788c39...@uu.nl>
Content-Type: text/plain; charset="utf-8"

SUMMER SCHOOL ON ADVANCED FUNCTIONAL PROGRAMMING

Online -  05-9 July 2021

 http://www.afp.school

# Call for Participation

## About

The Advanced Functional Programming summer school has been running for
more than ten years. We aim to educate aspiring Haskell programmers
beyond the basic material covered by many textbooks.

This year the course will be offered *online only*. A typical day will
consist a 2-3 hours of lectures, sandwiched between supervised lab
sessions. Lectures will be held in the (European) afternoon, but
recordings will be made available if attending live is problematic.

The lectures will cover several more advanced topics regarding
programming with types in Haskell, including topics such as:

   * monads and applicative functors;
   * lambda calculus;
   * generalized algebraic datatypes;
   * datatype generic programming
   * type families and type-level programming;

## Lecturers

Utrecht staff:
* Gabriele Keller
* Trevor McDonell
* Wouter Swierstra

## Prerequisites

We expect students to have a basic familiarity with Haskell
already. You should be able to write recursive functions over
algebraic data types, such as lists and trees. There is a great deal
of material readily available that covers this material. If you've
already started learning Haskell and are looking to take your
functional programming skills to the next level, this is the course
for you.

Soft registration deadline: 1 June, 2021
School: 05-09 July, 2021

## Costs

   50 euro - Registration fee

We ask ask participants to pay a small registration fee to cover some
of our organizational expenses. If this is problematic for you *for
whatever reason*, please let us know and we can waive your
registration fee.

## Further information

Further information, including instructions on how to register, is
available on our website:

   http://www.afp.school



--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 154, Issue 1
*


Beginners Digest, Vol 153, Issue 4

2021-04-10 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Strange use of undefined (et al.) in listcomprehension
  (Galaxy Being)
   2. Re:  Strange use of undefined (et al.) in listcomprehension
  (Matthew Low)
   3. Re:  Strange use of undefined (et al.) in listcomprehension
  (Matthew Low)


--

Message: 1
Date: Sat, 10 Apr 2021 10:49:07 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Strange use of undefined (et al.) in
listcomprehension
Message-ID:

Content-Type: text/plain; charset="utf-8"

So the Bool predicates and the generators are not purposefully grouped
separately -- it just appears that way from the simplistic beginner book
examples. But the evaluation is, indeed, left-to-right in that the first
example above has even x evaluated directly after x <- [1,3], whereas in
the second example the y <- undefined is evaluated directly after x <-
[1,3], then
the even x, correct? Again, the beginner book examples give the impression
that any and all predicates are A) always pushed to the far right, closest
to the right bracket, and B) follow no order of application such as being
bound to the form closest to the left. So yes, it's visually obvious that
there is an outer-inner looping happening when you see the output of two
generators doing combinations, but, again, the beginner treatments I've
seen make no explicit mention of order in an LC. This is all news to me,
but thanks! That's what these forums are for!



On Sat, Apr 10, 2021 at 12:18 AM Matthew Low  wrote:

> First, I'm confused about what is the input and what is the predicate
>
> The haskell 2010 report (
> https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-420003.11)
> says that after the | we can have any type of qualifier, which can be 1. a
> generator (I think you called this the input) 2. a local binding (we don't
> care about these in your example, there are none) or 3. boolean guards,
> which are any expression that evaluate to Bool (your predicates). So there
> isn't really a `predicate postion`, predicates can occur anywhere after the
> `|`.
>
> As for the behaviour, its easiest to see what happens with a regular list
> of inputs:
>
> λ> [(x,y) | x <- [1,2], y <- ['A', 'B']]
> [(1,'A'),(1,'B'),(2,'A'),(2,'B')]
>
> so `y` acts as an inner loop and `x` the outer.
>
> > [1 | x <- [1,3], even x, y <- undefined]
>>
> Here we start the outer loop over x, and only if x is even, then we loop
> over y. But x is never even, so we never loop over y, so we never evaluate
> `undefined` (Haskell is lazy). So essentially filter out all elements of x
> and are left with []
>
> > [1 | x <- [1,3], y <- undefined, even x]
>>
> Now we've moved the guard into the inner loop, after we try to evaluate y.
> So we blow up trying to do that and GHCi catches the exception
>
> [1 | x <- [1,3], y <- [1..], even x]
>>
> Similar to the above, the (even x) isn't guarding the evaluation of y, so
> we're stuck generating all the infinite pairings of x = 1, y = 1...
>
> On Fri, Apr 9, 2021 at 9:59 PM Galaxy Being  wrote:
>
>> I'm looking at Bird's *Thinking Functionally with Haskell *and he gives
>> two list comprehensions, asking under what conditions they deliver the same
>> results
>>
>> [e | x <- xs, p x, y <- ys]
>> [e | x <- xs, y <- ys, p x]
>>
>> First, I'm confused about what is the input and what is the predicate.
>> The y <- ys in the first LC seems to be in a predicate position, and in
>> the second it's a second input after x <- xs with p x in the predicate
>> position . . . confusing me.
>>
>> The answer examples Bird gives are beyond me:
>>
>> They deliver the same result only if ys is a finite list:
>>
>> > [1 | x <- [1,3], even x, y <- undefined]
>> []
>> > [1 | x <- [1,3], y <- undefined, even x]
>> Exception: Prelude.undefined
>> > [1 | x <- [1,3], y <- [1..], even x]
>> {Interruped}
>>
>> I'm not sure what's being said here, or what points are being made.
>>
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment 

Beginners Digest, Vol 153, Issue 3

2021-04-10 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Strange use of undefined (et al.) in listcomprehension
  (Galaxy Being)
   2. Re:  Strange use of undefined (et al.) in listcomprehension
  (Matthew Low)


--

Message: 1
Date: Fri, 9 Apr 2021 22:59:07 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Strange use of undefined (et al.) in list
comprehension
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm looking at Bird's *Thinking Functionally with Haskell *and he gives two
list comprehensions, asking under what conditions they deliver the same
results

[e | x <- xs, p x, y <- ys]
[e | x <- xs, y <- ys, p x]

First, I'm confused about what is the input and what is the predicate. The y
<- ys in the first LC seems to be in a predicate position, and in the
second it's a second input after x <- xs with p x in the predicate position
. . . confusing me.

The answer examples Bird gives are beyond me:

They deliver the same result only if ys is a finite list:

> [1 | x <- [1,3], even x, y <- undefined]
[]
> [1 | x <- [1,3], y <- undefined, even x]
Exception: Prelude.undefined
> [1 | x <- [1,3], y <- [1..], even x]
{Interruped}

I'm not sure what's being said here, or what points are being made.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 9 Apr 2021 23:17:20 -0600
From: Matthew Low 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Strange use of undefined (et al.) in
listcomprehension
Message-ID:

Content-Type: text/plain; charset="utf-8"

>
> First, I'm confused about what is the input and what is the predicate

The haskell 2010 report (
https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-420003.11)
says that after the | we can have any type of qualifier, which can be 1. a
generator (I think you called this the input) 2. a local binding (we don't
care about these in your example, there are none) or 3. boolean guards,
which are any expression that evaluate to Bool (your predicates). So there
isn't really a `predicate postion`, predicates can occur anywhere after the
`|`.

As for the behaviour, its easiest to see what happens with a regular list
of inputs:

λ> [(x,y) | x <- [1,2], y <- ['A', 'B']]
[(1,'A'),(1,'B'),(2,'A'),(2,'B')]

so `y` acts as an inner loop and `x` the outer.

> [1 | x <- [1,3], even x, y <- undefined]
>
Here we start the outer loop over x, and only if x is even, then we loop
over y. But x is never even, so we never loop over y, so we never evaluate
`undefined` (Haskell is lazy). So essentially filter out all elements of x
and are left with []

> [1 | x <- [1,3], y <- undefined, even x]
>
Now we've moved the guard into the inner loop, after we try to evaluate y.
So we blow up trying to do that and GHCi catches the exception

[1 | x <- [1,3], y <- [1..], even x]
>
Similar to the above, the (even x) isn't guarding the evaluation of y, so
we're stuck generating all the infinite pairings of x = 1, y = 1...

On Fri, Apr 9, 2021 at 9:59 PM Galaxy Being  wrote:

> I'm looking at Bird's *Thinking Functionally with Haskell *and he gives
> two list comprehensions, asking under what conditions they deliver the same
> results
>
> [e | x <- xs, p x, y <- ys]
> [e | x <- xs, y <- ys, p x]
>
> First, I'm confused about what is the input and what is the predicate. The y
> <- ys in the first LC seems to be in a predicate position, and in the
> second it's a second input after x <- xs with p x in the predicate
> position . . . confusing me.
>
> The answer examples Bird gives are beyond me:
>
> They deliver the same result only if ys is a finite list:
>
> > [1 | x <- [1,3], even x, y <- undefined]
> []
> > [1 | x <- [1,3], y <- undefined, even x]
> Exception: Prelude.undefined
> > [1 | x <- [1,3], y <- [1..], even x]
> {Interruped}
>
> I'm not sure what's being said here, or what points are being made.
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An 

Beginners Digest, Vol 153, Issue 2

2021-04-07 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Is map (map f) just map f? (Galaxy Being)
   2. Re:  Is map (map f) just map f? (Akhra Gannon)
   3. Re:  Is map (map f) just map f? (Galaxy Being)
   4. Re:  Is map (map f) just map f? (Ut Primum)


--

Message: 1
Date: Wed, 7 Apr 2021 11:47:03 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Is map (map f) just map f?
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm in Bird's *Thinking Functionally with Haskell* and the topic is natural
transformations. He says

filter p . map f = map f . filter (p . f)

and he has a proof, but one step of the proof he goes from

filter p . map f = concat . map (map f) . map (test (p . f))

to

filter p . map f = map f . concat . map (test (p . f))

which means

concat . map (map f) => map f . concat

which means

map (map f) = map f

... or I'm getting this step wrong somehow. To begin with, I'm having a
hard time comprehending map(map f), Any ideas on how this is possible?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Wed, 7 Apr 2021 10:06:47 -0700
From: Akhra Gannon 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Is map (map f) just map f?
Message-ID:

Content-Type: text/plain; charset="utf-8"

Check the types!

map :: (a -> b) -> [a] -> [b]

Therefore:

map f :: [a] -> [b]

map . map :: (a -> b) -> [[a]] -> [[b]]

map (map f) :: [[a]] -> [[b]]

And,

concat :: [[a]] -> [a]

Put it all together and you should see how that rewrite works!


On Wed, Apr 7, 2021, 9:47 AM Galaxy Being  wrote:

> I'm in Bird's *Thinking Functionally with Haskell* and the topic is
> natural transformations. He says
>
> filter p . map f = map f . filter (p . f)
>
> and he has a proof, but one step of the proof he goes from
>
> filter p . map f = concat . map (map f) . map (test (p . f))
>
> to
>
> filter p . map f = map f . concat . map (test (p . f))
>
> which means
>
> concat . map (map f) => map f . concat
>
> which means
>
> map (map f) = map f
>
> ... or I'm getting this step wrong somehow. To begin with, I'm having a
> hard time comprehending map(map f), Any ideas on how this is possible?
>
> LB
>
>
>
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Thu, 8 Apr 2021 00:03:32 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Is map (map f) just map f?
Message-ID:

Content-Type: text/plain; charset="utf-8"

So basically I can see that the type definitions would seem to deliver the
same thing. I test it

> (concat . (map (map (*5 [[1],[2],[3]]
[5,10,15]
> (map (*5) . concat) [[1],[2],[3]]
[5,10,15]

and can also conclude they give the same answer. So is this an example of
referential transparency, i.e., the ability to substitute code and be
assured both forms/expressions deliver the same answer?


On Wed, Apr 7, 2021 at 12:07 PM Akhra Gannon  wrote:

> Check the types!
>
> map :: (a -> b) -> [a] -> [b]
>
> Therefore:
>
> map f :: [a] -> [b]
>
> map . map :: (a -> b) -> [[a]] -> [[b]]
>
> map (map f) :: [[a]] -> [[b]]
>
> And,
>
> concat :: [[a]] -> [a]
>
> Put it all together and you should see how that rewrite works!
>
>
> On Wed, Apr 7, 2021, 9:47 AM Galaxy Being  wrote:
>
>> I'm in Bird's *Thinking Functionally with Haskell* and the topic is
>> natural transformations. He says
>>
>> filter p . map f = map f . filter (p . f)
>>
>> and he has a proof, but one step of the proof he goes from
>>
>> filter p . map f = concat . map (map f) . map (test (p . f))
>>
>> to
>>
>> filter p . map f = map f . concat . map (test (p . f))
>>
>> which means
>>
>> concat . map (map f) => map f . concat
>>
>> which means
>>
>> map 

Beginners Digest, Vol 153, Issue 1

2021-04-04 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Type class instance with Num (Galaxy Being)
   2. Re:  Type class instance with Num (Bob Ippolito)


--

Message: 1
Date: Sat, 3 Apr 2021 23:26:09 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Type class instance with Num
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm following LYHFGG and I have this

class YesNo a where
yesno :: a -> Bool

instance YesNo Int where
yesno 0 = False
yesno _ = True

but then I have to specify Int here

> yesno (5 :: Int)
True

Just with 5 gives this error

Ambiguous type variable ‘a0’ arising from the literal ‘5’
  prevents the constraint ‘(Num a0)’ from being solved.
  Probable fix: use a type annotation to specify what ‘a0’ should be.

I tried this

instance YesNo (Num a) where
yesno 0 = False
yesno _ = True

but got cryptic errors. What can I do to make yesno take any of Num's
numbers?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sat, 3 Apr 2021 21:39:23 -0700
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type class instance with Num
Message-ID:

Content-Type: text/plain; charset="utf-8"

You need something like this:

{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}

class YesNo a where
yesno :: a -> Bool

instance (Num a, Eq a) => YesNo a where
yesno = (/= 0)

The reason this doesn't work without turning on some "scary" flags is that
you can easily write code that is ambiguous since typeclasses are open.
Open means that some other file can define a data type that has an instance
of Num and an instance for YesNo and then there's no obvious choice which
instance should be used.

If you want a bit more detail, here's a relevant StackOverflow question:
https://stackoverflow.com/questions/8877541/how-to-write-an-instance-for-all-types-in-another-type-class


On Sat, Apr 3, 2021 at 9:26 PM Galaxy Being  wrote:

> I'm following LYHFGG and I have this
>
> class YesNo a where
> yesno :: a -> Bool
>
> instance YesNo Int where
> yesno 0 = False
> yesno _ = True
>
> but then I have to specify Int here
>
> > yesno (5 :: Int)
> True
>
> Just with 5 gives this error
>
> Ambiguous type variable ‘a0’ arising from the literal ‘5’
>   prevents the constraint ‘(Num a0)’ from being solved.
>   Probable fix: use a type annotation to specify what ‘a0’ should be.
>
> I tried this
>
> instance YesNo (Num a) where
> yesno 0 = False
> yesno _ = True
>
> but got cryptic errors. What can I do to make yesno take any of Num's
> numbers?
>
> LB
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 153, Issue 1
*


Beginners Digest, Vol 152, Issue 12

2021-03-30 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Problem with Graphics.SOE (Thomas Hallgren)
   2. Re:  Problem with Graphics.SOE (Vitaly Dolgov)


--

Message: 1
Date: Mon, 29 Mar 2021 14:32:38 +0200
From: Thomas Hallgren 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Problem with Graphics.SOE
Message-ID: 
Content-Type: text/plain; charset=UTF-8

Hi,

I did a quick grep in the HGL source code, and it looks like it is trying to use
a font called "9x15", which is one of the traditional X Windows fonts, and they
are not always installed by default on modern Linux systems. You can see which X
fonts are installed by running the xlsfonts command. In Ubuntu / Debian, the
"9x15" font is included in a package called xfonts-base, which is installed by
default however, so my best guess is that you are using another flavour of Linux
where you need to install some additional font package to get that font...

Hope this helps,
Thomas H

On 2021-03-29 12:18, Vitaly Dolgov wrote:
> Hi, everybody!
> 
> I'm trying to do an example from the book "The Haskell
> School of Expression", which originally uses `SOEGraphics`, I use
> `Graphics.SOE` instead, but I get the following error on each run:
> 
> `user error (loadQueryFont)`
> 
> I have no idea how to approach the problem... `:trace` outputs an empty
> exception :( Could you please help me to solve this?
> 
> My environment is: Linux, ghc 8.10.4, HGL 3.2.3.2
> The code is quite basic:
> 
> ```
> import Graphics.SOE
> 
> main
>= runGraphics $
>  do w <- openWindow "Hello World!" (300, 300)
> drawInWindow w (text (100, 200) "Hello World!")
> k <- getKey w
> closeWindow w
> ```
> 
> Thank you,
> Vitaly
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 




--

Message: 2
Date: Mon, 29 Mar 2021 19:10:05 +0300
From: Vitaly Dolgov 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Problem with Graphics.SOE
Message-ID: <20210329191005.0dccb015@yoga>
Content-Type: text/plain; charset=US-ASCII

Thanks, Thomas!

This was exactly the case. 

In Fedora the package is `xorg-x11-fonts-misc`.

Vitaly

On Mon, 29 Mar 2021 14:32:38 +0200
Thomas Hallgren  wrote:

> Hi,
> 
> I did a quick grep in the HGL source code, and it looks like it is
> trying to use a font called "9x15", which is one of the traditional X
> Windows fonts, and they are not always installed by default on modern
> Linux systems. You can see which X fonts are installed by running the
> xlsfonts command. In Ubuntu / Debian, the "9x15" font is included in
> a package called xfonts-base, which is installed by default however,
> so my best guess is that you are using another flavour of Linux where
> you need to install some additional font package to get that font...
> 
> Hope this helps,
> Thomas H
> 
> On 2021-03-29 12:18, Vitaly Dolgov wrote:
> > Hi, everybody!
> > 
> > I'm trying to do an example from the book "The Haskell
> > School of Expression", which originally uses `SOEGraphics`, I use
> > `Graphics.SOE` instead, but I get the following error on each run:
> > 
> > `user error (loadQueryFont)`
> > 
> > I have no idea how to approach the problem... `:trace` outputs an
> > empty exception :( Could you please help me to solve this?
> > 
> > My environment is: Linux, ghc 8.10.4, HGL 3.2.3.2
> > The code is quite basic:
> > 
> > ```
> > import Graphics.SOE
> > 
> > main
> >= runGraphics $
> >  do w <- openWindow "Hello World!" (300, 300)
> > drawInWindow w (text (100, 200) "Hello World!")
> > k <- getKey w
> > closeWindow w
> > ```
> > 
> > Thank you,
> > Vitaly
> > ___
> > Beginners mailing list
> > Beginners@haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> > 
> 
> 
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 12
**


Beginners Digest, Vol 152, Issue 11

2021-03-29 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Problem with Graphics.SOE (Vitaly Dolgov)


--

Message: 1
Date: Mon, 29 Mar 2021 13:18:49 +0300
From: Vitaly Dolgov 
To: beginners@haskell.org
Subject: [Haskell-beginners] Problem with Graphics.SOE
Message-ID: <20210329131849.75725a7b@yoga>
Content-Type: text/plain; charset=US-ASCII

Hi, everybody!

I'm trying to do an example from the book "The Haskell
School of Expression", which originally uses `SOEGraphics`, I use
`Graphics.SOE` instead, but I get the following error on each run:

`user error (loadQueryFont)`

I have no idea how to approach the problem... `:trace` outputs an empty
exception :( Could you please help me to solve this?

My environment is: Linux, ghc 8.10.4, HGL 3.2.3.2
The code is quite basic:

```
import Graphics.SOE

main
   = runGraphics $
 do w <- openWindow "Hello World!" (300, 300)
drawInWindow w (text (100, 200) "Hello World!")
k <- getKey w
closeWindow w
```

Thank you,
Vitaly


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 11
**


Beginners Digest, Vol 152, Issue 10

2021-03-28 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  How to include {-# LANGUAGE LambdaCase #-} at the ghci
  prompt (amin...@mailbox.org)


--

Message: 1
Date: Sat, 27 Mar 2021 13:52:35 -0600
From: "amin...@mailbox.org" 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to include {-# LANGUAGE
LambdaCase #-} at the ghci prompt
Message-ID: <20210327195235.GA21057@painter.painter>
Content-Type: text/plain; charset=utf-8

On Fri, Mar 26, 2021 at 06:31:53PM +0100, Francesco Ariis wrote:
> Il 26 marzo 2021 alle 12:20 Galaxy Being ha scritto:
> > I've got this code I've entered into the ghci by hand between :{ and :}
> > 
> > :{
> > {-# LANGUAGE LambdaCase #-}
> > data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show)
> > infixr 5 `Cons`
> > 
> > subst_c :: (a -> Bool)  -> (a, MyList a) -> MyList a
> > subst_c pred = \ case
> >  (_, Empty)-> Empty
> >  (n, Cons e t)
> >| pred e-> Cons n $ subst_c pred (n, t)
> >| otherwise -> Cons e $ subst_c pred (n, t)
> > :}
> > 
> 
> λ> :set -XLambdaCase

You can also start GHCi with it:

$ ghci -XLambdaCase

Tom


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 10
**


Beginners Digest, Vol 152, Issue 9

2021-03-27 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  How to include {-# LANGUAGE LambdaCase #-} atthe ghci
  prompt (Galaxy Being)
   2. Re:  How to include {-# LANGUAGE LambdaCase #-} at the ghci
  prompt (Francesco Ariis)
   3. Re:  How to include {-# LANGUAGE LambdaCase #-} at the ghci
  prompt (Galaxy Being)
   4.  Closure: exact wording (Galaxy Being)


--

Message: 1
Date: Fri, 26 Mar 2021 12:20:55 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] How to include {-# LANGUAGE LambdaCase
#-} at  the ghci prompt
Message-ID:

Content-Type: text/plain; charset="utf-8"

I've got this code I've entered into the ghci by hand between :{ and :}

:{
{-# LANGUAGE LambdaCase #-}
data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show)
infixr 5 `Cons`

subst_c :: (a -> Bool)  -> (a, MyList a) -> MyList a
subst_c pred = \ case
 (_, Empty)-> Empty
 (n, Cons e t)
   | pred e-> Cons n $ subst_c pred (n, t)
   | otherwise -> Cons e $ subst_c pred (n, t)
:}

but I keep getting the error

Illegal lambda-case (use -XLambdaCase)

This works fine inside an .hs file and :load and run at the prompt.
However, I'm using Emacs org-mode and need to keep everything limited to a
version of hand-entered :{ ... :}. Any suggestions?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 26 Mar 2021 18:31:53 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to include {-# LANGUAGE
LambdaCase #-} at the ghci prompt
Message-ID: <20210326173152.GA9876@extensa>
Content-Type: text/plain; charset=utf-8

Il 26 marzo 2021 alle 12:20 Galaxy Being ha scritto:
> I've got this code I've entered into the ghci by hand between :{ and :}
> 
> :{
> {-# LANGUAGE LambdaCase #-}
> data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show)
> infixr 5 `Cons`
> 
> subst_c :: (a -> Bool)  -> (a, MyList a) -> MyList a
> subst_c pred = \ case
>  (_, Empty)-> Empty
>  (n, Cons e t)
>| pred e-> Cons n $ subst_c pred (n, t)
>| otherwise -> Cons e $ subst_c pred (n, t)
> :}
> 

λ> :set -XLambdaCase


--

Message: 3
Date: Fri, 26 Mar 2021 16:17:19 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] How to include {-# LANGUAGE
LambdaCase #-} at the ghci prompt
Message-ID:

Content-Type: text/plain; charset="utf-8"

Exactly. Thanks.

On Fri, Mar 26, 2021 at 12:33 PM Francesco Ariis  wrote:

> Il 26 marzo 2021 alle 12:20 Galaxy Being ha scritto:
> > I've got this code I've entered into the ghci by hand between :{ and :}
> >
> > :{
> > {-# LANGUAGE LambdaCase #-}
> > data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show)
> > infixr 5 `Cons`
> >
> > subst_c :: (a -> Bool)  -> (a, MyList a) -> MyList a
> > subst_c pred = \ case
> >  (_, Empty)-> Empty
> >  (n, Cons e t)
> >| pred e-> Cons n $ subst_c pred (n, t)
> >| otherwise -> Cons e $ subst_c pred (n, t)
> > :}
> >
>
> λ> :set -XLambdaCase
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 4
Date: Fri, 26 Mar 2021 16:32:01 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Closure: exact wording
Message-ID:

Content-Type: text/plain; charset="utf-8"

I've got this

addTwo x y = x + y
aT5 = addTwo 5
> aT5 3
8

Is it right to say aT5 is a closure over 5, or a closure over addTwo 5?

LB
-- next 

Beginners Digest, Vol 152, Issue 8

2021-03-17 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Type * and * -> * (Galaxy Being)
   2.  Product/tuple type vs. ... (Galaxy Being)


--

Message: 1
Date: Tue, 16 Mar 2021 14:12:06 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type * and * -> *
Message-ID:

Content-Type: text/plain; charset="utf-8"

This is great stuff. I thank everybody.

On Sun, Mar 14, 2021 at 5:42 AM Erik Dominikus 
wrote:

> > There's something fundamental I'm missing.
>
> It is not necessarily true, but useful, to think that:
>
> - A *type is* a set of values.
> - A *kind* as a set of types.
> - The *kind* * is the set of all types.
> - The *kind* * -> * is the set of every function with domain * and
> codomain *.
> - The *type* T -> U is the set of every function with domain T and
> codomain U, if each of T and U is a type (a set of values).
>
> For example:
>
> - The type *Bool* is the set {False, True}.
> - The type *Maybe Bool* is the set {Nothing, Just False, Just True}.
> - *Maybe* is a function such that Maybe(T) = { Nothing } union { Just t |
> t in T }.
> - *Maybe* is not a type; *Maybe Bool* is a type.
> - *a -> a* is the set { \ x -> x }.
>
> Currying and application can happen at both the value level and the type
> level:
>
> - The kind of *Either* is ** -> * -> **.
> - The kind of *Either a* is ** -> **, if the kind of *a* is ***.
> - The kind of *Either a b* is ***, if the kind of *a* is *** and the kind
> of *b* is ***.
> - The type of *Just* is *a -> Maybe a*.
> - The type of *Just x* is *Maybe a*, if the type of *x* is *a*.
>
> > Why is it giving two separate treatments?
>
> It is to show the various ways one *can* 
> implement/represent/realize/concretize/encode/model
> a mathematical construction in Haskell.
>
> You *can* (do type-level programming in Haskell, use all features of C++,
> eat spaghetti with a straw, etc.), but the real question has always been:
> *should* you?
>
> > If anyone knows of a really thorough and definitive *and *understandable
> treatment of Haskell types, I'd appreciate it.
>
> If you mean Haskell 98, then the Haskell 98 Report [1] (especially Chapter
> 4) seems "thorough and definitive", but I don't know whether you will find
> it "understandable".
>
> If you mean the latest Haskell as implemented by GHC, I don't know.
>
> [1] https://www.haskell.org/onlinereport/
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 16 Mar 2021 14:34:26 -0500
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Product/tuple type vs. ...
Message-ID:

Content-Type: text/plain; charset="utf-8"

Reading this

I'm a bit confused but think I understand what is meant by a *product
*or *tuple
*type constructor such as

data Point a b = Pt a b

Because Point has no "logical or," (|) of more than one possible value set
such as

data Color = Red | Green | Blue

 it is automatically a tuple type? Also, it has no possible "consing" --
does that play a role?

data Things a = T1 a (Things a) | T2 a (Things a) | LastT a

Things is also parameterized just like Point, but, again, Things is not a
tuple type for the reasons above, e.g., just having one parameterized
constructor means automatically a tuple type, right?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 8
*


Beginners Digest, Vol 152, Issue 7

2021-03-14 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Type * and * -> * (Erik Dominikus)


--

Message: 1
Date: Sun, 14 Mar 2021 17:41:45 +0700
From: Erik Dominikus 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type * and * -> *
Message-ID:

Content-Type: text/plain; charset="utf-8"

> There's something fundamental I'm missing.

It is not necessarily true, but useful, to think that:

- A *type is* a set of values.
- A *kind* as a set of types.
- The *kind* * is the set of all types.
- The *kind* * -> * is the set of every function with domain * and codomain
*.
- The *type* T -> U is the set of every function with domain T and codomain
U, if each of T and U is a type (a set of values).

For example:

- The type *Bool* is the set {False, True}.
- The type *Maybe Bool* is the set {Nothing, Just False, Just True}.
- *Maybe* is a function such that Maybe(T) = { Nothing } union { Just t | t
in T }.
- *Maybe* is not a type; *Maybe Bool* is a type.
- *a -> a* is the set { \ x -> x }.

Currying and application can happen at both the value level and the type
level:

- The kind of *Either* is ** -> * -> **.
- The kind of *Either a* is ** -> **, if the kind of *a* is ***.
- The kind of *Either a b* is ***, if the kind of *a* is *** and the kind
of *b* is ***.
- The type of *Just* is *a -> Maybe a*.
- The type of *Just x* is *Maybe a*, if the type of *x* is *a*.

> Why is it giving two separate treatments?

It is to show the various ways one *can*
implement/represent/realize/concretize/encode/model
a mathematical construction in Haskell.

You *can* (do type-level programming in Haskell, use all features of C++,
eat spaghetti with a straw, etc.), but the real question has always been:
*should* you?

> If anyone knows of a really thorough and definitive *and *understandable
treatment of Haskell types, I'd appreciate it.

If you mean Haskell 98, then the Haskell 98 Report [1] (especially Chapter
4) seems "thorough and definitive", but I don't know whether you will find
it "understandable".

If you mean the latest Haskell as implemented by GHC, I don't know.

[1] https://www.haskell.org/onlinereport/
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 7
*


Beginners Digest, Vol 152, Issue 6

2021-03-13 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Type * and * -> * (Matthew Low)


--

Message: 1
Date: Sat, 13 Mar 2021 00:58:21 -0700
From: Matthew Low 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type * and * -> *
Message-ID:

Content-Type: text/plain; charset="utf-8"

Thanks for the book recommendation!

On Fri, Mar 12, 2021 at 11:52 PM Bob Ippolito  wrote:

> The first definition is only used as an analogy, it’s a way to represent
> Peano numbers as values.
>
> The second definition is only related to the first in that it uses the
> same concept. It is not a breakdown of the first one, it is a completely
> separate (and incompatible) way to represent Peano numbers at the type
> level (and only as types, notice there are no constructors). You can not
> define both of these in the same module with the same names.
>
> In Haskell a kind is (basically) the type of a type. In modern GHC to make
> it even more clear (and to free up * for type operators) you can say Type
> instead of *.
>
> Zero has the kind Type (or *) because it has no arguments, just like Zero
> has the type Peano because the constructor has no arguments.
>
> Succ has the kind Type -> Type because you pass it a Type as an argument
> to get a concrete Type. Maybe also has the kind Type -> Type, as does [].
>
> Generally, beginner Haskell doesn’t use any of this type level
> programming. If this is a topic of interest, I recommend this book:
> https://thinkingwithtypes.com
>
> On Fri, Mar 12, 2021 at 22:19 Galaxy Being  wrote:
>
>> I found this interesting page 
>> at Wiki Haskell. Confusing, however, is how it first establishes
>>
>> data Peano = Zero | Succ Peano
>>
>> It says
>>
>> Here Zero and Succ are values (constructors). Zero has type Peano,
>>  and Succ has type Peano -> Peano.
>>
>> but then it breaks down each member further a few lines later
>>
>> data Zero
>> data Succ a
>>
>> and then says
>>
>> Zero has kind *, and Succ has kind * -> *. The natural numbers are
>> represented by types (of kind *) Zero, Succ Zero, Succ (Succ Zero) etc.
>>
>> Why is it giving two separate treatments and what is meant by the * and *
>> -> * ? There's something fundamental I'm missing.
>>
>> If anyone knows of a really thorough and definitive *and *understandable
>> treatment of Haskell types, I'd appreciate it.
>>
>> LB
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 6
*


Beginners Digest, Vol 152, Issue 5

2021-03-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Type * and * -> * (Galaxy Being)
   2. Re:  Type * and * -> * (Bob Ippolito)
   3. Re:  Type * and * -> * (Matthew Low)


--

Message: 1
Date: Sat, 13 Mar 2021 00:18:26 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Type * and * -> *
Message-ID:

Content-Type: text/plain; charset="utf-8"

I found this interesting page  at
Wiki Haskell. Confusing, however, is how it first establishes

data Peano = Zero | Succ Peano

It says

Here Zero and Succ are values (constructors). Zero has type Peano,
 and Succ has type Peano -> Peano.

but then it breaks down each member further a few lines later

data Zero
data Succ a

and then says

Zero has kind *, and Succ has kind * -> *. The natural numbers are
represented by types (of kind *) Zero, Succ Zero, Succ (Succ Zero) etc.

Why is it giving two separate treatments and what is meant by the * and *
-> * ? There's something fundamental I'm missing.

If anyone knows of a really thorough and definitive *and *understandable
treatment of Haskell types, I'd appreciate it.

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 12 Mar 2021 22:52:13 -0800
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type * and * -> *
Message-ID:

Content-Type: text/plain; charset="utf-8"

The first definition is only used as an analogy, it’s a way to represent
Peano numbers as values.

The second definition is only related to the first in that it uses the same
concept. It is not a breakdown of the first one, it is a completely
separate (and incompatible) way to represent Peano numbers at the type
level (and only as types, notice there are no constructors). You can not
define both of these in the same module with the same names.

In Haskell a kind is (basically) the type of a type. In modern GHC to make
it even more clear (and to free up * for type operators) you can say Type
instead of *.

Zero has the kind Type (or *) because it has no arguments, just like Zero
has the type Peano because the constructor has no arguments.

Succ has the kind Type -> Type because you pass it a Type as an argument to
get a concrete Type. Maybe also has the kind Type -> Type, as does [].

Generally, beginner Haskell doesn’t use any of this type level programming.
If this is a topic of interest, I recommend this book:
https://thinkingwithtypes.com

On Fri, Mar 12, 2021 at 22:19 Galaxy Being  wrote:

> I found this interesting page  at
> Wiki Haskell. Confusing, however, is how it first establishes
>
> data Peano = Zero | Succ Peano
>
> It says
>
> Here Zero and Succ are values (constructors). Zero has type Peano,
>  and Succ has type Peano -> Peano.
>
> but then it breaks down each member further a few lines later
>
> data Zero
> data Succ a
>
> and then says
>
> Zero has kind *, and Succ has kind * -> *. The natural numbers are
> represented by types (of kind *) Zero, Succ Zero, Succ (Succ Zero) etc.
>
> Why is it giving two separate treatments and what is meant by the * and *
> -> * ? There's something fundamental I'm missing.
>
> If anyone knows of a really thorough and definitive *and *understandable
> treatment of Haskell types, I'd appreciate it.
>
> LB
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Fri, 12 Mar 2021 23:53:19 -0700
From: Matthew Low 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Type * and * -> *
Message-ID:

Content-Type: text/plain; charset="utf-8"

I can only answer some of your questions.

To start, perhaps an analogy would help: Kinds are to types 

Beginners Digest, Vol 152, Issue 4

2021-03-12 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Recursion with a self-defined type (Galaxy Being)
   2. Re:  Recursion with a self-defined type (Matthew Low)
   3. Re:  Recursion with a self-defined type (Galaxy Being)


--

Message: 1
Date: Fri, 12 Mar 2021 10:19:16 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Recursion with a self-defined type
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm trying to translate *The Little MLer *into Haskell. I've got this

data Shishkebab = Skewer | Onion Shishkebab | Lamb Shishkebab | Tomato
Shishkebab deriving Show

Then I have this which works

veggieKebab :: Shishkebab -> Bool
veggieKebab Skewer = True
veggieKebab (Onion (shk)) = veggieKebab shk
veggieKebab (Tomato (shk)) = veggieKebab shk
veggieKebab (Lamb (shk)) = False

> veggieKebab (Tomato (Onion (Tomato (Onion Skewer
True

but I'm wondering if I could do something like this

veggieKebab :: Shishkebab -> Bool
veggieKebab Skewer = True
veggieKebab (shkb (sk)) | (shkb == Onion) || (shkb == Tomato) = veggieKebab
sk
| otherwise = False


This doesn't work, giving a "Parse error in pattern: shkb". I've been
advised that I'm trying to treat what is a data constructor like a
variable, but I can't fathom what that means in this case. What I'm trying
to leverage is what I've learned from dealing with lists and recursion
through the consed list. So if effect I'm trying to recurse through a
consed Shishkebab object. It works in the first case, but hyow could I do
this in this more generic way like the second try does?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 12 Mar 2021 17:27:21 -0700
From: Matthew Low 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Recursion with a self-defined type
Message-ID:

Content-Type: text/plain; charset="utf-8"

Pattern matches in Haskell are based on matching specific data
constructors, with underscores `_` as a "match anything" mechanism. So one
way to achieve something like what you want is

veggieKebab :: Shishkebab -> Bool
veggieKebab Skewer = True
veggieKebab (Onion (shk)) = veggieKebab shk
veggieKebab (Tomato (shk)) = veggieKebab shk
veggieKebab _ = False

This works because the matches are considered in top-to-bottom order, so
the last case only matches if all the others fail to.

I'm not sure if it helps to build insight or not, but if you look at the
the types of your data constructors in GHCI, you get, for example:

λ> :t Onion
Onion :: Shishkebab -> Shishkebab

So even if you could pattern match as you wanted (veggieKebab (shkb (sk)) |
(shkb == Onion)), you'd still be stuck with the problem of trying to
compare two functions for equality, which isn't easy (and not something
Haskell lets you do for arbitrary functions). You could get close to what
you originally wrote by using a few more helper functions:

startsWithOnion :: Shishkebab -> Bool
startsWithOnion (Onion _) = True
startsWithOnion _ = False

startsWithTomato :: Shishkebab -> Bool
startsWithTomato (Tomato _) = True
startsWithTomato _ = False

restOfKebab :: Shishkebab -> Shishkebab
restOfKebab Skewer = Skewer
restOfKebab (Onion rst) = rst
restOfKebab (Tomato rst) = rst
restOfKebab (Lamb rst) = rst

veggieKebab :: Shishkebab -> Bool
veggieKebab Skewer = True
veggieKebab kebab | startsWithOnion kebab || startsWithTomato kebab =
veggieKebab (restOfKebab kebab)
  | otherwise = False



On Fri, Mar 12, 2021 at 9:19 AM Galaxy Being  wrote:

> I'm trying to translate *The Little MLer *into Haskell. I've got this
>
> data Shishkebab = Skewer | Onion Shishkebab | Lamb Shishkebab | Tomato
> Shishkebab deriving Show
>
> Then I have this which works
>
> veggieKebab :: Shishkebab -> Bool
> veggieKebab Skewer = True
> veggieKebab (Onion (shk)) = veggieKebab shk
> veggieKebab (Tomato (shk)) = veggieKebab shk
> veggieKebab (Lamb (shk)) = False
>
> > veggieKebab (Tomato (Onion (Tomato (Onion Skewer
> True
>
> but I'm wondering if I could do something like this
>
> veggieKebab :: Shishkebab -> Bool
> veggieKebab Skewer = True

Beginners Digest, Vol 152, Issue 3

2021-03-07 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Maybe problems converting back to number (Galaxy Being)
   2. Re:  Maybe problems converting back to number (Francesco Ariis)
   3. Re:  Maybe problems converting back to number (Galaxy Being)


--

Message: 1
Date: Sat, 6 Mar 2021 09:53:30 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Maybe problems converting back to number
Message-ID:

Content-Type: text/plain; charset="utf-8"

I've got this example from the Internet

import Data.List
import Data.Maybe

firstFactorOf x
| m == Nothing = x
| otherwise = fromJust m
where m =(find p [2..x-1])
  p y = mod x y == 0

and this as a crude return the nth element of a list

import Data.List
import Data.Maybe

-- myIndex :: [a] -> Int -> Maybe a
myIndex [] _ = Nothing
myIndex (x:xs) 0 = Just x
myIndex (x:xs) n = myIndex xs (n-1)

I would like the Just x in the second block to actually be fromJust x as in
the first block, i.e., I want a number returned, not a Just typed object.
I've tried changing Just x to fromJust x but get the error when I try to
use it

> myIndex [1,2,3,4,5] 3

 * Non type-variable argument
: in the constraint: Num (Maybe (Maybe a))
:   (Use FlexibleContexts to permit this)
: * When checking the inferred type
: it :: forall a. Num (Maybe (Maybe a)) => Maybe a

What am I missing here? Also, my type declaration seems to be wrong too,
but I don't see why.

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sat, 6 Mar 2021 17:52:16 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Maybe problems converting back to
number
Message-ID: <20210306165216.GB2849@extensa>
Content-Type: text/plain; charset=utf-8

Il 06 marzo 2021 alle 09:53 Galaxy Being ha scritto:
> I've got this example from the Internet
> 
> import Data.List
> import Data.Maybe
> 
> firstFactorOf x
> | m == Nothing = x
> | otherwise = fromJust m
> where m =(find p [2..x-1])
>   p y = mod x y == 0
> 
> -- myIndex :: [a] -> Int -> Maybe a
> myIndex [] _ = Nothing
> myIndex (x:xs) 0 = Just x
> myIndex (x:xs) n = myIndex xs (n-1)
> 
> I would like the Just x in the second block to actually be fromJust x as in
> the first block, i.e., I want a number returned, not a Just typed object.
> I've tried changing Just x to fromJust x but get the error when I try to
> use it

What would happen in the `Nothing` case? If an error is fine with you:

myUnsafeIndex :: [a] -> Int -> a
myUnsafeIndex as n =
case myIndex as n of
  Nothing -> error "Chiare, fresche et dolci acque"
 -- or maybe return -1? Idk
  Just r -> r

What have you written instead

> Also, my type declaration seems to be wrong too, but I don't see why.

It compiles fine here, even if I remove the comment from `myIndex`
signature
—F


--

Message: 3
Date: Sat, 6 Mar 2021 22:17:26 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Maybe problems converting back to
number
Message-ID:

Content-Type: text/plain; charset="utf-8"

Here's what I finally did

myIndex'' l n
  | m == Nothing = error "No list."
  | otherwise = fromJust m
  where m = mI l n
mI [] _ = Nothing
mI (h:t) n | n == 0 = Just h
   | otherwise = mI t (n-1)

but then I can't say why I went to this extra step.



On Sat, Mar 6, 2021 at 10:53 AM Francesco Ariis  wrote:

> Il 06 marzo 2021 alle 09:53 Galaxy Being ha scritto:
> > I've got this example from the Internet
> >
> > import Data.List
> > import Data.Maybe
> >
> > firstFactorOf x
> > | m == Nothing = x
> > | otherwise = fromJust m
> > where m =(find p [2..x-1])
> >   p y = mod x y == 0
> >
> > -- myIndex :: [a] -> Int -> Maybe a
> > myIndex [] _ = Nothing
> > myIndex (x:xs) 0 = Just x
> > myIndex (x:xs) n = myIndex xs (n-1)
> >
> > I would like the Just x in the second block to actually be fromJust x as
> in
> > the first block, i.e., I 

Beginners Digest, Vol 152, Issue 2

2021-03-06 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Alphanumerical input (A. Mc.)


--

Message: 1
Date: Fri, 5 Mar 2021 21:31:23 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Alphanumerical input
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

I was wondering what the best way was for tranforming a list of
alphanumerical characters from main IO() such as:

Enter String:
A 101 E 182

and tranforming it into an Int list of

[0, 101, 4, 182]

Which converting A and E to 0 and 4 is easy enough with toEnum/fromEnum and
simple subtraction, and using read can convert to a [Char], but recognizing
101 as a single Int from a Char string in main, and getting both converted
together as part of the same function, I'm a bit less sure of without
resorting to much lower level imperative methods.

Thanks in advance and thank you for your time.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 2
*


Beginners Digest, Vol 152, Issue 1

2021-03-03 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Creating a Triple List from a List (David McBride)


--

Message: 1
Date: Tue, 2 Mar 2021 09:19:14 -0500
From: David McBride 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Creating a Triple List from a List
Message-ID:

Content-Type: text/plain; charset="utf-8"

If you are okay with a library, you can use the split library for this.

stack exec --package split -- ghci
>chunksOf 2 [1,2,3,4,5,6]
[[1,2],[3,4],[5,6]]

On Sat, Feb 27, 2021 at 9:08 PM A. Mc. <47dragonf...@gmail.com> wrote:

> Hello,
>
> What is the best way to take:
> [1, 2, 3, 4 ]
>
> And convert it to:
>
> [ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ]
>
> so that each member pair is:
>
> [ [1], [2] ]
>
> roughly analogous to a 1x2 vector?
>
> Thanks in advance and thank you for your time.
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 152, Issue 1
*


Beginners Digest, Vol 151, Issue 14

2021-02-28 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Bounded number types? (stuebinm)
   2.  Creating a Triple List from a List (A. Mc.)
   3. Re:  Creating a Triple List from a List (Francesco Ariis)


--

Message: 1
Date: Sat, 27 Feb 2021 19:00:27 +0100
From: stuebinm 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Bounded number types?
Message-ID: <004ce73c-486d-be27-bccc-68a7f00aa...@disroot.org>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi all,

I'm wondering: is there any type that represents e.g. a floating point 
value that is guaranteed to be within some interval (e.g. [0,1]?).

My practical use-case would be that I'm reading in input data from json, 
which may be ill-behaved — obviously I could just manually check, and 
then keep track of which numbers in which record fields are within which 
intervals, but coming from less strongly typed programming languages I 
wonder if there would be a "typed" way to do this, too.
-- next part --
A non-text attachment was scrubbed...
Name: OpenPGP_0x695C841098BECF1D.asc
Type: application/pgp-keys
Size: 3131 bytes
Desc: not available
URL: 

-- next part --
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: 


--

Message: 2
Date: Sat, 27 Feb 2021 18:07:21 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Creating a Triple List from a List
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

What is the best way to take:
[1, 2, 3, 4 ]

And convert it to:

[ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ]

so that each member pair is:

[ [1], [2] ]

roughly analogous to a 1x2 vector?

Thanks in advance and thank you for your time.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Sun, 28 Feb 2021 03:29:27 +0100
From: Francesco Ariis 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Creating a Triple List from a List
Message-ID: <20210228022927.GA30216@extensa>
Content-Type: text/plain; charset=utf-8

Il 27 febbraio 2021 alle 18:07 A. Mc. ha scritto:
> Hello,
> 
> What is the best way to take:
> [1, 2, 3, 4 ]
> 
> And convert it to:
> 
> [ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ]
> 
> so that each member pair is:
> 
> [ [1], [2] ]
> 
> roughly analogous to a 1x2 vector?

A 1×2 vector would be

> [[1  2], [3, 4]]

am I wrong? If so, a quick and dirty solution could be

d2 :: [a] -> [[a]]
d2 [] = []
d2 [a] = error "odd element"
d2 as = let (is, es) = splitAt 2 as
in is : d2 es
-- λ> d2 [1..6]
-- [[1,2],[3,4],[5,6]]




--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 14
**


Beginners Digest, Vol 151, Issue 13

2021-02-27 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Closure clear-up? (Galaxy Being)


--

Message: 1
Date: Fri, 26 Feb 2021 12:28:30 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Closure clear-up?
Message-ID:

Content-Type: text/plain; charset="utf-8"

>From my moving-target understanding of closures, I'm guessing this has a
closure

let succ = add 1
add x = xadder
  where xadder y = x + y
in succ 3

Now, can someone explain in words how the closure system is at work here? I
see that the add 1 is being "baked in". Do we say this is a closure on add 1?
(Closure wording is confusing.) The enclosing scope of add contains 1;
however, xadder is what succ ultimately becomes, which has 1 in its scope
in that when xadder is defined, the x argument will be the 1 of add 1. Or
am I missing something?

Researching closures vis-a-vis Haskell, I've seen the argument that,


   - no, Haskell doesn't have closures,
   - yes, Haskell is lazy, *everything* can be seen as a closure, as even a
   value can be seen as a function without argument waiting to be evaluated
   (and so capturing its environment until it gets evaluated).

This was taken from an older Haskell textbook (*Introduction to Functional
Programming Systems Using Haskell *by Davie).

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 13
**


Beginners Digest, Vol 151, Issue 12

2021-02-25 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Non-exhaustive patterns in function error (Galaxy Being)
   2. Re:  Non-exhaustive patterns in function error (Francesco Ariis)
   3. Re:  Non-exhaustive patterns in function error (Bob Ippolito)
   4. Re:  Non-exhaustive patterns in function error (Galaxy Being)
   5. Re:  Non-exhaustive patterns in function error (Brody Berg)


--

Message: 1
Date: Thu, 25 Feb 2021 17:23:46 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Non-exhaustive patterns in function error
Message-ID:

Content-Type: text/plain; charset="utf-8"

I have this

intersect1 :: ([a],[a]) -> [a]
intersect1 (s,[])  = []
interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts)
| otherwise = intersect1 (s,ts)

and when I try this

intersect1 ([1,2],[1,2,3])

I get the error

 Non-exhaustive patterns in function intersect1

Not sure what's wrong with this.

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 26 Feb 2021 00:45:41 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Non-exhaustive patterns in function
error
Message-ID: <20210225234541.GA31267@extensa>
Content-Type: text/plain; charset=us-ascii

Il 25 febbraio 2021 alle 17:23 Galaxy Being ha scritto:
> I have this
> 
> intersect1 :: ([a],[a]) -> [a]
> intersect1 (s,[])  = []
> interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts)
> | otherwise = intersect1 (s,ts)
> 
> and when I try this
> 
> intersect1 ([1,2],[1,2,3])
> 
> I get the error
> 
>  Non-exhaustive patterns in function intersect1
> 
> Not sure what's wrong with this.

Pattern (_,[]) is not matched!


--

Message: 3
Date: Thu, 25 Feb 2021 15:52:30 -0800
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Non-exhaustive patterns in function
error
Message-ID:

Content-Type: text/plain; charset="utf-8"

It's the typo. Note that you'll also need an Eq a typeclass constraint for
this type signature to be correct (which is the next error you'd get)

-- underscores for emphasis
inter_se_ct1
inter_es_ct1


On Thu, Feb 25, 2021 at 3:24 PM Galaxy Being  wrote:

> I have this
>
> intersect1 :: ([a],[a]) -> [a]
> intersect1 (s,[])  = []
> interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts)
> | otherwise = intersect1 (s,ts)
>
> and when I try this
>
> intersect1 ([1,2],[1,2,3])
>
> I get the error
>
>  Non-exhaustive patterns in function intersect1
>
> Not sure what's wrong with this.
>
> LB
>
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 4
Date: Thu, 25 Feb 2021 20:00:41 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Non-exhaustive patterns in function
error
Message-ID:

Content-Type: text/plain; charset="utf-8"

How embarrassing...

intersect1 :: (Eq a) => ([a],[a]) -> [a]


On Thu, Feb 25, 2021 at 5:53 PM Bob Ippolito  wrote:

> It's the typo. Note that you'll also need an Eq a typeclass constraint for
> this type signature to be correct (which is the next error you'd get)
>
> -- underscores for emphasis
> inter_se_ct1
> inter_es_ct1
>
>
> On Thu, Feb 25, 2021 at 3:24 PM Galaxy Being  wrote:
>
>> I have this
>>
>> intersect1 :: ([a],[a]) -> [a]
>> intersect1 (s,[])  = []
>> interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts)
>> | otherwise = intersect1 (s,ts)
>>
>> and when I try this
>>
>> intersect1 ([1,2],[1,2,3])
>>
>> I get the error
>>
>>  Non-exhaustive patterns in function intersect1
>>
>> Not sure what's wrong with this.
>>
>> LB
>>

Beginners Digest, Vol 151, Issue 11

2021-02-21 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Using Fractional Type (A. Mc.)
   2. Re:  Using Fractional Type (Bob Ippolito)
   3. Re:  Using Fractional Type (David James)


--

Message: 1
Date: Sat, 20 Feb 2021 11:59:07 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Using Fractional Type
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

I need to create a function that does: mod (recip x) y.  However, I am
getting all kinds of errors with the type signature.  Is there a better way
to use Fractional type than needing to enable FlexibleContexts?  What do I
need to do to still make use of Haskell's type system, but also still be
able to perform operations such as reciprocal (and division into fractions
for that matter).

Thanks in advance and thank you for your time.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sat, 20 Feb 2021 15:11:18 -0800
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Using Fractional Type
Message-ID:

Content-Type: text/plain; charset="utf-8"

I think what you're looking for is the mod' function from Data.Fixed. The
mod function only works with Integral types, FlexibleContexts wouldn't be
helpful for this.


On Sat, Feb 20, 2021 at 12:00 PM A. Mc. <47dragonf...@gmail.com> wrote:

> Hello,
>
> I need to create a function that does: mod (recip x) y.  However, I am
> getting all kinds of errors with the type signature.  Is there a better way
> to use Fractional type than needing to enable FlexibleContexts?  What do I
> need to do to still make use of Haskell's type system, but also still be
> able to perform operations such as reciprocal (and division into fractions
> for that matter).
>
> Thanks in advance and thank you for your time.
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Sun, 21 Feb 2021 08:41:52 +
From: David James 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Using Fractional Type
Message-ID:



Content-Type: text/plain; charset="windows-1252"

Also, I wonder if you’re typing:
> 5 mod 2

This does give a FlexibleContexts error. You should type either:
> mod 5 2
or
> 5 `mod` 2

(or, using mod’ as suggested):
> 5.5 `mod'` 1.3

You can read about prefix and infix notation 
here.

David.

From: Bob Ippolito
Sent: 20 February 2021 23:11
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level 
topics related to Haskell
Subject: Re: [Haskell-beginners] Using Fractional Type

I think what you're looking for is the mod' function from Data.Fixed. The mod 
function only works with Integral types, FlexibleContexts wouldn't be helpful 
for this.


On Sat, Feb 20, 2021 at 12:00 PM A. Mc. 
<47dragonf...@gmail.com> wrote:
Hello,

I need to create a function that does: mod (recip x) y.  However, I am getting 
all kinds of errors with the type signature.  Is there a better way to use 
Fractional type than needing to enable FlexibleContexts?  What do I need to do 
to still make use of Haskell's type system, but also still be able to perform 
operations such as reciprocal (and division into fractions for that matter).

Thanks in advance and thank you for your time.
___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer


Beginners Digest, Vol 151, Issue 10

2021-02-18 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  import question (Daniel Trstenjak)


--

Message: 1
Date: Thu, 18 Feb 2021 08:32:49 +0100
From: Daniel Trstenjak 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] import question
Message-ID: <20210218073249.GA5914@octa>
Content-Type: text/plain; charset=us-ascii

On Wed, Feb 17, 2021 at 02:17:32PM -0600, Galaxy Being wrote:
> How would I install it globally? I'm not using projects, I'm just at the ghci 
> REPL.

Even for such small tests it's simpler to just use a cabal project:

   mkdir decimal-test
   cd decimal-test
   cabal init -p decimal-test -d base -d Decimal
   cabal repl

If you need further dependencies you can then extend the 'build-depends'
list in the file 'decimal-test.cabal'.

Greetings,
Daniel


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 10
**


Beginners Digest, Vol 151, Issue 9

2021-02-17 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  import question (Bob Ippolito)
   2. Re:  import question (Galaxy Being)
   3. Re:  import question (Bob Ippolito)


--

Message: 1
Date: Wed, 17 Feb 2021 18:36:45 -0800
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] import question
Message-ID:

Content-Type: text/plain; charset="utf-8"

You don't need to do any rounding if the list is already Decimal.

If you wanted to format a Double with some specific decimal representation
you could look at Numeric.showFFloatAlt or similar.

import Data.Decimal

dList :: [Decimal]
dList = [1.00,1.01..2.00]

main = print dList



On Wed, Feb 17, 2021 at 5:27 PM Galaxy Being  wrote:

> I'm trying to create a list of real numbers with a two-decimal interval, a
> la
>
> > [1.0,1.01,1.02,...1.99,2.00]
>
> however, I get the float approximation problem
>
>
> [1.0,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.1,1.11,1.12,1.1301,1.1401,...
>
> So I attempted to compensate with
>
> import Data.Decimal
> map (roundTo 2) [1.00,1.01..2.0]
>
> I don't have to do it this way if there is another rounding function to
> correct the float overrun issue.
>
>
>
> On Wed, Feb 17, 2021 at 2:43 PM Francesco Ariis  wrote:
>
>> Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto:
>> > How would I install it globally? I'm not using projects, I'm just at the
>> > ghci REPL.
>>
>> Most likely
>>
>> cabal install --lib Decimal
>>
>> Check what Tom has said too —F
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Wed, 17 Feb 2021 21:42:02 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] import question
Message-ID:

Content-Type: text/plain; charset="utf-8"

As I've said, working at the ghci REPL,

import Data.Decimal
dList :: [Decimal]
dList = [1.00,1.01..2.00]
main = print dList

errors out

: :76:11-17: error:
: Not in scope: type constructor or class `Decimal'



On Wed, Feb 17, 2021 at 8:37 PM Bob Ippolito  wrote:

> You don't need to do any rounding if the list is already Decimal.
>
> If you wanted to format a Double with some specific decimal representation
> you could look at Numeric.showFFloatAlt or similar.
>
> import Data.Decimal
>
> dList :: [Decimal]
> dList = [1.00,1.01..2.00]
>
> main = print dList
>
>
>
> On Wed, Feb 17, 2021 at 5:27 PM Galaxy Being  wrote:
>
>> I'm trying to create a list of real numbers with a two-decimal interval,
>> a la
>>
>> > [1.0,1.01,1.02,...1.99,2.00]
>>
>> however, I get the float approximation problem
>>
>>
>> [1.0,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.1,1.11,1.12,1.1301,1.1401,...
>>
>> So I attempted to compensate with
>>
>> import Data.Decimal
>> map (roundTo 2) [1.00,1.01..2.0]
>>
>> I don't have to do it this way if there is another rounding function to
>> correct the float overrun issue.
>>
>>
>>
>> On Wed, Feb 17, 2021 at 2:43 PM Francesco Ariis  wrote:
>>
>>> Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto:
>>> > How would I install it globally? I'm not using projects, I'm just at
>>> the
>>> > ghci REPL.
>>>
>>> Most likely
>>>
>>> cabal install --lib Decimal
>>>
>>> Check what Tom has said too —F
>>> ___
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An 

Beginners Digest, Vol 151, Issue 8

2021-02-17 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Add Global Package (Jeffrey Brown)
   2.  import question (Galaxy Being)
   3. Re:  import question (Francesco Ariis)
   4. Re:  import question (amin...@mailbox.org)
   5. Re:  import question (Galaxy Being)
   6. Re:  import question (Francesco Ariis)
   7. Re:  import question (Galaxy Being)


--

Message: 1
Date: Wed, 17 Feb 2021 08:07:19 -0500
From: Jeffrey Brown 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Add Global Package
Message-ID:

Content-Type: text/plain; charset="utf-8"

If you use Stack then you can add a .cabal file to your project that
indicates what it depends on. Here's an example I use:

https://github.com/JeffreyBenjaminBrown/montevideo/blob/master/mtv-util/mtv-util.cabal

(It uses the `random` package too; if you search for "random"  you'll find
the dependencies.)

Stack has global config options too:
https://docs.haskellstack.org/en/stable/yaml_configuration/
which seems likely to offer the same capability; I don't know how to do it
that way as I always work within a project with a cabal file.

On Wed, Feb 17, 2021 at 2:08 AM Francesco Ariis  wrote:

> Il 16 febbraio 2021 alle 20:49 A. Mc. ha scritto:
> > I'm attempting to install and update the .yaml file so I don't have to
> run
> > the command $ stack ghci --package random every single time I want to
> load
> > a module that imports System.Random.  Or maybe I need to use chocolatey?
>
> No idea with stack, but with cabal is:
>
> cabal install --lib random
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


-- 
Jeff Brown | Jeffrey Benjamin Brown
LinkedIn    |   Github
   |   Twitter
  |  Facebook
  |  very old Website

-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Wed, 17 Feb 2021 11:13:19 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] import question
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm trying to use Decimal but (I'm guessing) I don't know how to import it.

import Data.Decimal

dList :: [Decimal]
dList = [1.1,1.2..2.0]

: :70:11-17: error:
: Not in scope: type constructor or class `Decimal'

Obviously I was asleep the day the teacher told us how to do this. . . .

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Wed, 17 Feb 2021 19:57:00 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] import question
Message-ID: <20210217185700.GA30720@extensa>
Content-Type: text/plain; charset=utf-8

Il 17 febbraio 2021 alle 11:13 Galaxy Being ha scritto:
> I'm trying to use Decimal but (I'm guessing) I don't know how to import it.
> 
> import Data.Decimal
> 
> dList :: [Decimal]
> dList = [1.1,1.2..2.0]
> 
> : :70:11-17: error:
> : Not in scope: type constructor or class `Decimal'

Works here. You need to add `Decimal` the dependencies of your project
or install it globally first
—F


--

Message: 4
Date: Wed, 17 Feb 2021 12:58:35 -0700
From: "amin...@mailbox.org" 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] import question
Message-ID: <20210217195835.GA18315@painter.painter>
Content-Type: text/plain; charset=us-ascii

Is it possible you mean to use Double or Float instead of Decimal?

Tom

On Wed, Feb 17, 2021 at 11:13:19AM -0600, Galaxy Being wrote:
> I'm trying to use Decimal but (I'm guessing) I don't know how to import it.
> 
> import Data.Decimal
> 
> dList :: [Decimal]
> dList = [1.1,1.2..2.0]
> 
> : :70:11-17: error:
> : Not in scope: type constructor 

Beginners Digest, Vol 151, Issue 7

2021-02-17 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Add Global Package (A. Mc.)
   2. Re:  Add Global Package (Francesco Ariis)


--

Message: 1
Date: Tue, 16 Feb 2021 20:49:38 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Add Global Package
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

I'm attempting to install and update the .yaml file so I don't have to run
the command $ stack ghci --package random every single time I want to load
a module that imports System.Random.  Or maybe I need to use chocolatey?  I
don't know, but being able to use System.Random like every other package
would be greatly appreciated.  Right now, I'm not sure what command I need
to use to do that.

Thanks in advance and thank you for your time.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Wed, 17 Feb 2021 08:07:33 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Add Global Package
Message-ID: <20210217070732.GA23243@extensa>
Content-Type: text/plain; charset=us-ascii

Il 16 febbraio 2021 alle 20:49 A. Mc. ha scritto:
> I'm attempting to install and update the .yaml file so I don't have to run
> the command $ stack ghci --package random every single time I want to load
> a module that imports System.Random.  Or maybe I need to use chocolatey?

No idea with stack, but with cabal is:

cabal install --lib random


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 7
*


Beginners Digest, Vol 151, Issue 6

2021-02-14 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Recursive calls inside lazy data constructors? (Galaxy Being)


--

Message: 1
Date: Sat, 13 Feb 2021 14:34:02 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Recursive calls inside lazy data
constructors?
Message-ID:

Content-Type: text/plain; charset="utf-8"

I was wondering about why he calls this a "data constructor". Is this a
general use of the idea of "date constructor?"

On Sat, Feb 13, 2021 at 1:50 AM Ut Primum  wrote:

> Hi,
> the sequence defined in your example has been conjectured by Collatz to be
> finite for all initial n. But by now this property hasn't been proved.
> So, for what we know, there could be an integer such that the sequence
> starting form it is infinite (no such n has been found yet, but there could
> be one).
> Anyway, even if such n existed, you chose it, and wrote
>
> x=collatz n
>
> there would not be a stack overflow. This is because computations will be
> done "lazily", so just when really needed. So if you asked for the first,
> say, 10 elements of the list x, they would be computed without problems,
> even if the base case is never reached. Of course if you asked to print
> collatz n for an n that makes the sequence infinite, the printing would
> never end. But you could make many operations with the possibly infinite
> list, if they required just a finite (not necessarily a priori bounded)
> number of elements.
>
> So in Haskell you can define lists or other data structures that are
> infinite. Of course you must define the structure in such a way that to
> compute the "next" element of the list there is no need to look at "future"
> elements, but just at "past" ones.
>
> I hope this answers your question,
> Cheers,
> Ut
>
> Il sab 13 feb 2021, 00:03 Galaxy Being  ha scritto:
>
>> I'm looking at this
>> 
>> from Stackoverflow and wondering what is meant in the accepted answer when
>> he says
>>
>> *In Haskell you can safely do recursive calls inside lazy data
>> constructors, and there will be no risk of stack overflow or divergence.
>> Placing the recursive call inside a constructor eliminates the need for an
>> accumulator, and the order of elements in the list will also correspond to
>> the order in which they are computed*:
>>
>> collatz :: Integer -> [Integer]
>> collatz n | n <= 1 = []
>> collatz n = n : collatz next where
>> next = if even n then div n 2 else n * 3 + 1
>>
>> What is meant by lazy data constructor in this context?
>>
>> LB
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 6
*


Beginners Digest, Vol 151, Issue 5

2021-02-13 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Recursive calls inside lazy data constructors? (Galaxy Being)
   2. Re:  Recursive calls inside lazy data constructors? (Ut Primum)


--

Message: 1
Date: Fri, 12 Feb 2021 17:01:44 -0600
From: Galaxy Being 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Recursive calls inside lazy data
constructors?
Message-ID:

Content-Type: text/plain; charset="utf-8"

I'm looking at this

from Stackoverflow and wondering what is meant in the accepted answer when
he says

*In Haskell you can safely do recursive calls inside lazy data
constructors, and there will be no risk of stack overflow or divergence.
Placing the recursive call inside a constructor eliminates the need for an
accumulator, and the order of elements in the list will also correspond to
the order in which they are computed*:

collatz :: Integer -> [Integer]
collatz n | n <= 1 = []
collatz n = n : collatz next where
next = if even n then div n 2 else n * 3 + 1

What is meant by lazy data constructor in this context?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Sat, 13 Feb 2021 08:49:48 +0100
From: Ut Primum 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Recursive calls inside lazy data
constructors?
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hi,
the sequence defined in your example has been conjectured by Collatz to be
finite for all initial n. But by now this property hasn't been proved.
So, for what we know, there could be an integer such that the sequence
starting form it is infinite (no such n has been found yet, but there could
be one).
Anyway, even if such n existed, you chose it, and wrote

x=collatz n

there would not be a stack overflow. This is because computations will be
done "lazily", so just when really needed. So if you asked for the first,
say, 10 elements of the list x, they would be computed without problems,
even if the base case is never reached. Of course if you asked to print
collatz n for an n that makes the sequence infinite, the printing would
never end. But you could make many operations with the possibly infinite
list, if they required just a finite (not necessarily a priori bounded)
number of elements.

So in Haskell you can define lists or other data structures that are
infinite. Of course you must define the structure in such a way that to
compute the "next" element of the list there is no need to look at "future"
elements, but just at "past" ones.

I hope this answers your question,
Cheers,
Ut

Il sab 13 feb 2021, 00:03 Galaxy Being  ha scritto:

> I'm looking at this
> 
> from Stackoverflow and wondering what is meant in the accepted answer when
> he says
>
> *In Haskell you can safely do recursive calls inside lazy data
> constructors, and there will be no risk of stack overflow or divergence.
> Placing the recursive call inside a constructor eliminates the need for an
> accumulator, and the order of elements in the list will also correspond to
> the order in which they are computed*:
>
> collatz :: Integer -> [Integer]
> collatz n | n <= 1 = []
> collatz n = n : collatz next where
> next = if even n then div n 2 else n * 3 + 1
>
> What is meant by lazy data constructor in this context?
>
> LB
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 5

Beginners Digest, Vol 151, Issue 4

2021-02-06 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Mixed division (Lawrence Bottorff)
   2. Re:  Mixed division (Ut Primum)
   3. Re:  Mixed division (Lawrence Bottorff)
   4.  Cabal Build (A. Mc.)
   5.  Function with mod cases? (Lawrence Bottorff)


--

Message: 1
Date: Fri, 5 Feb 2021 12:22:52 -0600
From: Lawrence Bottorff 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] Mixed division
Message-ID:

Content-Type: text/plain; charset="utf-8"

I can divide a float by an integer

>  2.4 / 3
0.7999

but why can I not do this?

< 2.4 / (length [1,2,3])
:288:1-22: error:
* No instance for (Fractional Int) arising from a use of `/'
* In the expression: 2.4 / (length [1, 2, 3])

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 5 Feb 2021 19:28:51 +0100
From: Ut Primum 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Mixed division
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hi,
when you write 3 Haskell sees it as a "num" while the type of the length
[1,2,3] is "int". So 3 and length [1,2,3] have not the same type.

Il ven 5 feb 2021, 19:23 Lawrence Bottorff  ha scritto:

> I can divide a float by an integer
>
> >  2.4 / 3
> 0.7999
>
> but why can I not do this?
>
> < 2.4 / (length [1,2,3])
> :288:1-22: error:
> * No instance for (Fractional Int) arising from a use of `/'
> * In the expression: 2.4 / (length [1, 2, 3])
>
> LB
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Fri, 5 Feb 2021 12:36:03 -0600
From: Lawrence Bottorff 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Mixed division
Message-ID:

Content-Type: text/plain; charset="utf-8"

This works

myAvg :: [Float] -> Float
myAvg [] = 0.0
myAvg xs = (foldr (+) 0.0 xs) / (fromIntegral (length xs) :: Float)

but is there a simpler way to "cast" the value of (length xs)?

On Fri, Feb 5, 2021 at 12:29 PM Ut Primum  wrote:

> Hi,
> when you write 3 Haskell sees it as a "num" while the type of the length
> [1,2,3] is "int". So 3 and length [1,2,3] have not the same type.
>
> Il ven 5 feb 2021, 19:23 Lawrence Bottorff  ha scritto:
>
>> I can divide a float by an integer
>>
>> >  2.4 / 3
>> 0.7999
>>
>> but why can I not do this?
>>
>> < 2.4 / (length [1,2,3])
>> :288:1-22: error:
>> * No instance for (Fractional Int) arising from a use of `/'
>> * In the expression: 2.4 / (length [1, 2, 3])
>>
>> LB
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 4
Date: Fri, 5 Feb 2021 16:42:52 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Cabal Build
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

I've been trying to do a cabal build.  I'm using Windows 10.  But, after
going through cabal init, change diretories, run, etc it keeps telling me I
don't have permission.  My project also has 2 libraries that I wrote for
main, and although I tried editing the .cabal file, I'm not sure I have it
right.

Thanks in advance and thank you for your time.
-- next part --
An HTML attachment was scrubbed...
URL: 

Beginners Digest, Vol 151, Issue 3

2021-02-05 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  type variables - error: 'No instance for' (Corrado Corrado)
   2. Re:  type variables - error: 'No instance for' (David James)


--

Message: 1
Date: Fri, 5 Feb 2021 07:27:06 +0100
From: Corrado Corrado 
To: beginners@haskell.org
Subject: [Haskell-beginners] type variables - error: 'No instance for'
Message-ID:



Content-Type: text/plain; charset="utf-8"

An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 5 Feb 2021 09:41:54 +
From: David James 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] type variables - error: 'No instance
for'
Message-ID:



Content-Type: text/plain; charset="cp1253"

Hello,

Have a look at this:

> mytriple (1 :: Integer) 'a' 'b'
:418:28: error:
• Couldn't match expected type ‘Integer’ with actual type ‘Char’
• In the third argument of ‘mytriple’, namely ‘'b'’
  In the expression: mytriple (1 :: Integer) 'a' 'b'
  In an equation for ‘it’: it = mytriple (1 :: Integer) 'a' 'b'

This is probably what you expected. In this case, you’ve explicitly stated that 
1 is a value of type Integer.

But look at the type here:

> :t 3
3 :: Num p => p

This might be a bit confusing. Haskell supports many different types of number 
(Int, Integer, Double, Complex, etc). Although they are different types, they 
are all instances of the same class (Num). When you type 1 (or some other 
numeric literal) into GHCi, it doesn’t (yet) know which of these types you 
want, but does know it has to be a type that’s an instance of Num, which is 
what the type signature gives. Hence you can do:

> 3 `mod` 2
1
(which treats the 3 as some integral type), or

> 3 / 2
1.5
(which treats the 3 as a fractional – i.e. non-integral- type)

Now it knows more about the type of 3 needed, it will ensure it is of a more 
specific type.

If typeclasses are new to you, you might want to read something like 
this.

Now look at:

> :t (+)
(+) :: Num a => a -> a -> a

This says (+) can add two values of the same type, as long as that type is an 
instance of class Num. Hence:

> 3 + 'a'
:407:1: error:
• No instance for (Num Char) arising from a use of ‘+’
• In the expression: 3 + 'a'
  In an equation for ‘it’: it = 3 + 'a'

This now makes sense: ‘a’ is of type Char, and there is no instance declaration 
instance Num Char (since Char’s are not numbers).

Your example is much the same. In order for mytriple 1 'a' 'b' to typecheck: 
‘b’ must be a Char, and 1 must also be a Char, but 1 has to be a type that’s an 
instance of Num, so would require an instance Num Char to exist.

Hope that all makes sense,
David.

From: Corrado Corrado
Sent: 05 February 2021 06:27
To: beginners@haskell.org
Subject: [Haskell-beginners] type variables - error: 'No instance for'

Hello,
I defined a simple function as below:

mytriple :: a -> b -> a -> (a,b,a);
mytriple x y z = (x,y,z);

Then I checked 'mytriple' type variables signatures, so I declared a mytriple 
values in a 'wrong way':

  should be to the same type of the 1st argument
/
λ:t2 = mytriple 1 'a' 'b'
 error:
'No instance for (Num Char) arising from the literal '1'
'In the first argument of mytriple', namely '1'
  In the expression: mytriple 1 'a' 'b'
  In an equation for 't2': t2 = mytriple 1 'a' 'b'

Ok, this is exactly what I aspected, but I do not understand the error.

What means the sentence : 'No instance for (Num Char) arising from the literal 
'1'.'
How is evaluated a function, in order to check that the params are type 
variables signatures?

Why the error message refers to the 1st arguments?

Thanks
Conrad




-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



Beginners Digest, Vol 151, Issue 2

2021-02-04 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Data Types and Functions Visualization
  (Leduin José Cuenca Macas)


--

Message: 1
Date: Wed, 3 Feb 2021 16:01:51 -0500
From: Leduin José Cuenca Macas  
To: beginners@haskell.org
Subject: [Haskell-beginners] Data Types and Functions Visualization
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hey, there! Do you know about any tool to generate a graph that connects
data types through functions of my program? I tried stack dot but only I
obtained the relationship of dependencies.

Greetings!


*Leduin José Cuenca Macas*
*Student | Estudiante*
Tel. (+593) 991 618 273
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 2
*


Beginners Digest, Vol 151, Issue 1

2021-02-01 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Using Functions with Fold (A. Mc.)
   2. Re:  Using Functions with Fold (Francesco Ariis)


--

Message: 1
Date: Sun, 31 Jan 2021 20:49:39 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Using Functions with Fold
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

I feel like I need to go back to basics, so I've made a toy problem that
takes a list of Ints, say [10, 20, 30, 40, 50, 60] and, in theory, iterates
through the list in successive pairs i.e. [10, 20], [20, 30], [30, 40],
[40, 50], [50, 60] and looks for a specific pair set, say 30, 40, and
accumulates the number of times that pair appears in the list (for example
purpose, there are no repeats, but assuming there were).  What I've
done is the following:

---take starting at position 2, in increments of 2 with overlap allowed
takeAtTwo :: [Int] -> Int -> [Int]
takeAtTwo list position = take (2 + position) list

---expects range of 0 to length list - 2
grabTwo :: [Int] -> Int -> [Int]
grabTwo list position = drop position (takeAtTwo list position)

-- and this does NOT work, half-pseudocode
--- pass in a pair of Int, say [30, 40] and sum up the number of appearances
numPair list = foldr (\pair acc -> if grabTwo list iterator == pair then
acc + 1 else acc) 0

However, I am unsure how to get this to work properly with fold.
Suggestions? Thanks in advance and thank you for your time.
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Mon, 1 Feb 2021 06:07:32 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Using Functions with Fold
Message-ID: <20210201050732.GA21439@extensa>
Content-Type: text/plain; charset=utf-8

Il 31 gennaio 2021 alle 20:49 A. Mc. ha scritto:
> I feel like I need to go back to basics, so I've made a toy problem that
> takes a list of Ints, say [10, 20, 30, 40, 50, 60] and, in theory, iterates
> through the list in successive pairs i.e. [10, 20], [20, 30], [30, 40],
> [40, 50], [50, 60] and looks for a specific pair set, say 30, 40, and
> accumulates the number of times that pair appears in the list (for example
> purpose, there are no repeats, but assuming there were).  What I've
> done is the following:
> 
> ---take starting at position 2, in increments of 2 with overlap allowed
> takeAtTwo :: [Int] -> Int -> [Int]
> takeAtTwo list position = take (2 + position) list
> 
> ---expects range of 0 to length list - 2
> grabTwo :: [Int] -> Int -> [Int]
> grabTwo list position = drop position (takeAtTwo list position)
> 
> -- and this does NOT work, half-pseudocode
> --- pass in a pair of Int, say [30, 40] and sum up the number of appearances
> numPair list = foldr (\pair acc -> if grabTwo list iterator == pair then
> acc + 1 else acc) 0
> 
> However, I am unsure how to get this to work properly with fold.
> Suggestions? Thanks in advance and thank you for your time.

You might have better luck with first generating the pairs and then
passing them to another function.

λ> prova as = zip as (tail as)
λ> prova [10,20..60]
[(10,20),(20,30),(30,40),(40,50),(50,60)]

Counting now is a simple matter of

λ> length . filter (==(30,40)) $ it
1
-- or use a fold if you prefer



--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 151, Issue 1
*


Beginners Digest, Vol 150, Issue 17

2021-01-29 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  GHCi Debugging (A. Mc.)
   2. Re:  GHCi Debugging (Francesco Ariis)


--

Message: 1
Date: Thu, 28 Jan 2021 22:04:10 -0800
From: "A. Mc." <47dragonf...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] GHCi Debugging
Message-ID:

Content-Type: text/plain; charset="utf-8"

Hello,

I suspect that the function recursion composition I have used is not
working very well, so I'm trying to learn how to use the debugger to
understand what is going on, except I don't really understand the output of
the GHCi debugger or what is going on very well.   I have a main function
called 'Analysis' in a library that analyzes a string.  I've used :break
Analysis and then called :trace and then repeatedly typed :continue, but
there are a number of steps between one continue and the next
return-and-call of output that I'm not sure I understand. Suggestions on
better debugging methods, or even how to fully understand this output,
would be very helpful.  Thanks in advance.

_result :: Bool = _
key :: Int = -18
message :: [Char] = _
[Lib.hs:17:8-69] *Main> :continue
Stopped in Main.Analysis, Lib.hs:18:8-84
_result :: Bool = _
key :: Int = -18
message :: [Char] = _
[Lib.hs:18:8-84] *Main> :continue
Stopped in Main.Analysis, Lib.hs:19:8-65
_result :: Bool = _
key :: Int = -18
message :: [Char] = "esleespmwfpdvjtdgpcjmwfpzgpcespcp"
[Lib.hs:19:8-65] *Main> :continue
Stopped in Main.Analysis, Lib.hs:19:70-127
_result :: (Int, Text) = _
key :: Int = -18
message :: [Char] = "esleespmwfpdvjtdgpcjmwfpzgpcespcp"
[Lib.hs:19:70-127] *Main> :continue
Stopped in Main.Analysis, Lib.hs:15:8-14
_result :: Bool = _
key :: Int = _
[Lib.hs:15:8-14] *Main> :continue
Stopped in Main.Analysis, Lib.hs:16:8-70
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Fri, 29 Jan 2021 07:19:46 +0100
From: Francesco Ariis 
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] GHCi Debugging
Message-ID: <20210129061946.GA7871@extensa>
Content-Type: text/plain; charset=us-ascii

Il 28 gennaio 2021 alle 22:04 A. Mc. ha scritto:
> I suspect that the function recursion composition I have used is not
> working very well, so I'm trying to learn how to use the debugger to
> understand what is going on, except I don't really understand the output of
> the GHCi debugger or what is going on very well.   I have a main function
> called 'Analysis' in a library that analyzes a string.  I've used :break
> Analysis and then called :trace and then repeatedly typed :continue, but
> there are a number of steps between one continue and the next
> return-and-call of output that I'm not sure I understand. Suggestions on
> better debugging methods, or even how to fully understand this output,
> would be very helpful.  Thanks in advance.

For pure functions, debug [1] is Godsent.

[1] https://hackage.haskell.org/package/debug


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 150, Issue 17
**


Beginners Digest, Vol 150, Issue 16

2021-01-27 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Defined list data type compared to Haskell   List
  (David McBride)
   2.  As pattern, @ (Lawrence Bottorff)
   3. Re:  As pattern, @ (Ut Primum)


--

Message: 1
Date: Tue, 26 Jan 2021 18:14:27 -0500
From: David McBride 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Defined list data type compared to
Haskell List
Message-ID:

Content-Type: text/plain; charset="utf-8"

You can, you have to write it slightly differently. But defined that way it
can only ever have one element because NList only takes one.

mylist = NList (NList (NList (Elem 1)))

You could also change it to

data NestedList a = Elem a | NList a (NestedList a)

But at that point you have a nonempty list type (always at least one
element) which already exists.

On Tue, Jan 26, 2021, 17:40 Lawrence Bottorff  wrote:

> Why can I not do this?
>
> data NestedList1 a = Elem a | NList (NestedList1 a)
>
> that is, with parens rather than square brackets, then
>
> myList2 = (NList (Elem 1, NList (Elem 2, NList (Elem 3, Elem 4), Elem 5)))
>
> It gives the error
>
> :383:18-73: error:
> ,* Couldn't match expected type `NestedList1 a'
>   with actual type `(NestedList1 Integer, NestedList1 a0)'
> ,* In the first argument of `NList', namely
> `(Elem 1, NList (Elem 2, NList (Elem 3, Elem 4), Elem 5))'
>   In the expression:
> (NList (Elem 1, NList (Elem 2, NList (Elem 3, Elem 4), Elem 5)))
>   In an equation for `myList2':
>   myList2
> = (NList (Elem 1, NList (Elem 2, NList (Elem 3, Elem 4), Elem
> 5)))
> ,* Relevant bindings include
> myList2 :: NestedList1 a (bound at :383:1)
>
> etc., etc.
>
> On Tue, Jan 26, 2021 at 4:05 PM David McBride  wrote:
>
>> Right that is a plain list of NestedLists.  So if you were to rewrite [a]
>> as (Regularlist a) so to speak (not a real type), the definition of
>> NestedList would be List (RegularList (NestedList a)).
>>
>> Keep in mind that List is a constructor, everything after it is types.
>>
>> On Tue, Jan 26, 2021 at 4:50 PM Lawrence Bottorff 
>> wrote:
>>
>>> So NestedList is using regular List? So in
>>>
>>> data NestedList a = Elem a | List [NestedList a]
>>>
>>> the second data constructor List [NestedList a] we see a "regular" list
>>> because of the square brackets?
>>>
>>> On Tue, Jan 26, 2021 at 3:42 PM David McBride  wrote:
>>>
 In NestedList, the List constructor takes a regular list of
 NestedLists.  Therefore when pattern matching on it you can get access to
 those nested lists.  In your code, x is the first NestedList, and xs is the
 rest of the NestedLists.

 On Tue, Jan 26, 2021 at 4:32 PM Lawrence Bottorff 
 wrote:

> I'm following this 
> and yet I see this solution
>
> data NestedList a = Elem a | List [NestedList a] deriving (Show)
>
> flatten1 :: NestedList a -> [a]
> flatten1 (Elem a   )   = [a]
> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
> flatten1 (List []) = []
>
> What I find puzzling is this line
>
> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
>
> where I see
>
> (List (x:xs)) as an argument. How is the NestedList type also able to
> be expressed as a normal consed list with x:xs argument? How is (:)
> interacting with NestedList?
>
> LB
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
 ___
 Beginners mailing list
 Beginners@haskell.org
 http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

>>> ___
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part 

Beginners Digest, Vol 150, Issue 15

2021-01-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Defined list data type compared to Haskell   List
  (Lawrence Bottorff)
   2. Re:  Defined list data type compared to Haskell   List
  (David McBride)
   3. Re:  Defined list data type compared to Haskell   List
  (Lawrence Bottorff)


--

Message: 1
Date: Tue, 26 Jan 2021 15:49:26 -0600
From: Lawrence Bottorff 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Defined list data type compared to
Haskell List
Message-ID:

Content-Type: text/plain; charset="utf-8"

So NestedList is using regular List? So in

data NestedList a = Elem a | List [NestedList a]

the second data constructor List [NestedList a] we see a "regular" list
because of the square brackets?

On Tue, Jan 26, 2021 at 3:42 PM David McBride  wrote:

> In NestedList, the List constructor takes a regular list of NestedLists.
> Therefore when pattern matching on it you can get access to those nested
> lists.  In your code, x is the first NestedList, and xs is the rest of the
> NestedLists.
>
> On Tue, Jan 26, 2021 at 4:32 PM Lawrence Bottorff 
> wrote:
>
>> I'm following this 
>> and yet I see this solution
>>
>> data NestedList a = Elem a | List [NestedList a] deriving (Show)
>>
>> flatten1 :: NestedList a -> [a]
>> flatten1 (Elem a   )   = [a]
>> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
>> flatten1 (List []) = []
>>
>> What I find puzzling is this line
>>
>> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
>>
>> where I see
>>
>> (List (x:xs)) as an argument. How is the NestedList type also able to be
>> expressed as a normal consed list with x:xs argument? How is (:)
>> interacting with NestedList?
>>
>> LB
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 26 Jan 2021 17:04:54 -0500
From: David McBride 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] Defined list data type compared to
Haskell List
Message-ID:

Content-Type: text/plain; charset="utf-8"

Right that is a plain list of NestedLists.  So if you were to rewrite [a]
as (Regularlist a) so to speak (not a real type), the definition of
NestedList would be List (RegularList (NestedList a)).

Keep in mind that List is a constructor, everything after it is types.

On Tue, Jan 26, 2021 at 4:50 PM Lawrence Bottorff  wrote:

> So NestedList is using regular List? So in
>
> data NestedList a = Elem a | List [NestedList a]
>
> the second data constructor List [NestedList a] we see a "regular" list
> because of the square brackets?
>
> On Tue, Jan 26, 2021 at 3:42 PM David McBride  wrote:
>
>> In NestedList, the List constructor takes a regular list of NestedLists.
>> Therefore when pattern matching on it you can get access to those nested
>> lists.  In your code, x is the first NestedList, and xs is the rest of the
>> NestedLists.
>>
>> On Tue, Jan 26, 2021 at 4:32 PM Lawrence Bottorff 
>> wrote:
>>
>>> I'm following this 
>>> and yet I see this solution
>>>
>>> data NestedList a = Elem a | List [NestedList a] deriving (Show)
>>>
>>> flatten1 :: NestedList a -> [a]
>>> flatten1 (Elem a   )   = [a]
>>> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
>>> flatten1 (List []) = []
>>>
>>> What I find puzzling is this line
>>>
>>> flatten1 (List (x:xs)) = flatten1 x ++ flatten1 (List xs)
>>>
>>> where I see
>>>
>>> (List (x:xs)) as an argument. How is the NestedList type also able to be
>>> expressed as a normal consed list with x:xs argument? How is (:)
>>> interacting with NestedList?
>>>
>>> LB
>>> ___
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> 

Beginners Digest, Vol 150, Issue 14

2021-01-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  $ versus . (Lawrence Bottorff)
   2. Re:  $ versus . (Bob Ippolito)
   3.  Defined list data type compared to Haskell List
  (Lawrence Bottorff)
   4. Re:  Defined list data type compared to Haskell   List
  (David McBride)


--

Message: 1
Date: Tue, 26 Jan 2021 10:23:12 -0600
From: Lawrence Bottorff 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:

Content-Type: text/plain; charset="utf-8"

> :t (init tail)
: error:
: * Couldn't match expected type `[a]'
:   with actual type `[a0] -> [a0]'
: * Probable cause: `tail' is applied to too few arguments
:   In the first argument of `init', namely `tail'
:   In the expression: (init tail)

> :t (init . tail)
: (init . tail) :: [a] -> [a]

> :t init $ tail
: error:
* Couldn't match expected type `[a]'
  with actual type `[a0] -> [a0]'
* Probable cause: `tail' is applied to too few arguments
  In the second argument of `($)', namely `tail'
  In the expression: init $ tail

> chopEnds = init $ tail
> chopEnds [1,2,3]
error: ...
* Variable not in scope: chopEnds1 :: [Integer] -> t
...

but then

> init $ tail [1,2,3]
[2]

Not sure what I'm missing here. It doesn't make sense to me that the last
expression works, but no version of a closure

chopEnds = init $ tail

does.

On Mon, Jan 25, 2021 at 7:58 PM Kim-Ee Yeoh  wrote:

> init $ tail [1,2,3]
> = init (tail ([1,2,3])) -- a la Lisp
>
> Now, functional programming is awesomest at abstractions. What if we could
> abstract out "init (tail"?
>
> Then we could write
>
> chopEnds = init (tail
>
> But that looks weird. It's only got the left half of a parens pair!
>
> Does that explain why you should not expect the same result?
>
> A separate question is why the compiler even type-checks "init $ tail" in
> the first place. What do you think is going on there?
>
> On Tue, Jan 26, 2021 at 1:16 AM Lawrence Bottorff 
> wrote:
>
>> I've got this
>>
>> > init $ tail [1,2,3]
>> [2]
>>
>> and this
>>
>> > chopEnds = init $ tail
>> > chopEnds [1,2,3]
>> [1,2]
>>
>> What happened? Why is it not just init $ tail [1,2,3] ?
>>
>> This works fine
>>
>> > chopEnds2 = init . tail
>> > chopEnds2 [1,2,3]
>> [2]
>>
>> What am I missing?
>>
>> LB
>> ___
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> --
> -- Kim-Ee
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Tue, 26 Jan 2021 09:25:03 -0800
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:

Content-Type: text/plain; charset="utf-8"

The difference is that one of them is:

— unnecessary parentheses for emphasis
(init tail) [1, 2, 3]

And the other is

— parentheses required for correct evaluation
init (tail [1, 2, 3])

On Tue, Jan 26, 2021 at 08:23 Lawrence Bottorff  wrote:

> > :t (init tail)
> : error:
> : * Couldn't match expected type `[a]'
> :   with actual type `[a0] -> [a0]'
> : * Probable cause: `tail' is applied to too few arguments
> :   In the first argument of `init', namely `tail'
> :   In the expression: (init tail)
>
> > :t (init . tail)
> : (init . tail) :: [a] -> [a]
>
> > :t init $ tail
> : error:
> * Couldn't match expected type `[a]'
>   with actual type `[a0] -> [a0]'
> * Probable cause: `tail' is applied to too few arguments
>   In the second argument of `($)', namely `tail'
>   In the expression: init $ tail
>
> > chopEnds = init $ tail
> > chopEnds [1,2,3]
> error: ...
> * Variable not in scope: chopEnds1 :: [Integer] -> t
> ...
>
> but then
>
> > init $ tail [1,2,3]
> [2]
>
> Not sure what I'm missing here. It doesn't make sense to me that the last
> expression works, but no version of a closure
>
> chopEnds = init $ 

Beginners Digest, Vol 150, Issue 13

2021-01-26 Thread beginners-request
Send Beginners mailing list submissions to
beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
beginners-requ...@haskell.org

You can reach the person managing the list at
beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  $ versus . (Lawrence Bottorff)
   2. Re:  $ versus . (Bob Ippolito)
   3. Re:  $ versus . (Kim-Ee Yeoh)


--

Message: 1
Date: Mon, 25 Jan 2021 12:16:05 -0600
From: Lawrence Bottorff 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: [Haskell-beginners] $ versus .
Message-ID:

Content-Type: text/plain; charset="utf-8"

I've got this

> init $ tail [1,2,3]
[2]

and this

> chopEnds = init $ tail
> chopEnds [1,2,3]
[1,2]

What happened? Why is it not just init $ tail [1,2,3] ?

This works fine

> chopEnds2 = init . tail
> chopEnds2 [1,2,3]
[2]

What am I missing?

LB
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Mon, 25 Jan 2021 11:18:20 -0800
From: Bob Ippolito 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:

Content-Type: text/plain; charset="utf-8"

I think what you're missing is what you actually typed in the first case.

This is a type error, it will not compile or run:

chopEnds = init $ tail

The $ operator can always be rewritten as parentheses, in this case:

chopEnds = init (tail)

Which has the same incorrectly typed meaning as:

chopEnds = init tail

The "result" you pasted looks equivalent to:

chopEnds = init

Perhaps this is what you typed? In this case the argument tail it will
shadow the existing binding of the Prelude tail, which would be confusing
so with -Wall it would issue a compiler warning:

chopEnds tail = init $ tail

:2:10: warning: [-Wname-shadowing]
This binding for ‘tail’ shadows the existing binding
  imported from ‘Prelude’ (and originally defined in ‘GHC.List’)


On Mon, Jan 25, 2021 at 10:16 AM Lawrence Bottorff 
wrote:

> I've got this
>
> > init $ tail [1,2,3]
> [2]
>
> and this
>
> > chopEnds = init $ tail
> > chopEnds [1,2,3]
> [1,2]
>
> What happened? Why is it not just init $ tail [1,2,3] ?
>
> This works fine
>
> > chopEnds2 = init . tail
> > chopEnds2 [1,2,3]
> [2]
>
> What am I missing?
>
> LB
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 3
Date: Tue, 26 Jan 2021 08:58:11 +0700
From: Kim-Ee Yeoh 
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:

Content-Type: text/plain; charset="utf-8"

init $ tail [1,2,3]
= init (tail ([1,2,3])) -- a la Lisp

Now, functional programming is awesomest at abstractions. What if we could
abstract out "init (tail"?

Then we could write

chopEnds = init (tail

But that looks weird. It's only got the left half of a parens pair!

Does that explain why you should not expect the same result?

A separate question is why the compiler even type-checks "init $ tail" in
the first place. What do you think is going on there?

On Tue, Jan 26, 2021 at 1:16 AM Lawrence Bottorff  wrote:

> I've got this
>
> > init $ tail [1,2,3]
> [2]
>
> and this
>
> > chopEnds = init $ tail
> > chopEnds [1,2,3]
> [1,2]
>
> What happened? Why is it not just init $ tail [1,2,3] ?
>
> This works fine
>
> > chopEnds2 = init . tail
> > chopEnds2 [1,2,3]
> [2]
>
> What am I missing?
>
> LB
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
-- Kim-Ee
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Subject: Digest Footer

___
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


--

End of Beginners Digest, Vol 150, Issue 13

  1   2   3   4   5   6   7   8   9   10   >