
Hi, safeHead.hs safeHead :: [a] -> Maybe a safeHead [] = Nothing safeHead (x:_) = Just x prelude> safeHead [23,1,4,2,4,2] Just 23 Question: what am i doing wrong? best, Alexander

I expected
prelude> safeHead [23,1,4,2,4,2]
23
not
Just 23
May 13, 2020 4:11:47 PM CEST Imants Cekusins

The function returns Maybe a.
On Wed, May 13, 2020 at 5:16 PM Alexander Chen
I expected
prelude> safeHead [23,1,4,2,4,2] 23
not Just 23
May 13, 2020 4:11:47 PM CEST Imants Cekusins
wrote: prelude> safeHead [23,1,4,2,4,2] Just 23
Looks good.
What did you expect to see?
_______________________________________________ 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

Maybe a is a sum type. Show instance for sum types displays the constructor. For example, if we used another sum type: Either Int Int, then Left 23 /= Right 23 So we'd be interested to see the constructor to tell them apart. 23 wouldn't be sufficiently clear. On Wed, May 13, 2020 at 5:18 PM Velichko Lefterov < velichko.lefterov@gmail.com> wrote:
The function returns Maybe a.
On Wed, May 13, 2020 at 5:16 PM Alexander Chen
wrote: I expected
prelude> safeHead [23,1,4,2,4,2] 23
not Just 23
May 13, 2020 4:11:47 PM CEST Imants Cekusins
wrote: prelude> safeHead [23,1,4,2,4,2] Just 23
Looks good.
What did you expect to see?
_______________________________________________ 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

Actually, derived Show instance for _any_ type displays the constructor. I hope this statement is correct ;)
participants (3)
-
Alexander Chen
-
Imants Cekusins
-
Velichko Lefterov