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.  No ghci return for homemade types (Lawrence Bottorff)
   2. Re:  No ghci return for homemade types (Francesco Ariis)


----------------------------------------------------------------------

Message: 1
Date: Sun, 3 Jan 2021 16:22:12 -0600
From: Lawrence Bottorff <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] No ghci return for homemade types
Message-ID:
        <CAFAhFSXHSyoinnL3tsVpV=tabzacerjwm1ddjvzk0prntyk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I've tried this

data MyMaybe a = Just a | Nothing

maybeHead :: [t] -> MyMaybe t
maybeHead [] = Nothing
maybeHead (x:_) = Just x

and it evaluates fine. But this

maybeHead [1,2,3]

produces error:
:     • No instance for (Show (MyMaybe Integer))
:         arising from a use of ‘show’
:     • In the expression: show (maybeHead [1, 2, 3])
:       In an equation for ‘it’: it = show (maybeHead [1, 2, 3])

Similarly,

data Color a = Blue a | Green a | Red a

myFavoriteColor :: Color Int
myFavoriteColor = Green 50

but now I'm stuck. How can I access the "Green 50" inside myFavoriteColor?

LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210103/0f32d09e/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 3 Jan 2021 23:29:26 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] No ghci return for homemade types
Message-ID: <20210103222926.GA9403@extensa>
Content-Type: text/plain; charset=utf-8

Il 03 gennaio 2021 alle 16:22 Lawrence Bottorff ha scritto:
> I've tried this
> 
> data MyMaybe a = Just a | Nothing
> 
> maybeHead :: [t] -> MyMaybe t
> maybeHead [] = Nothing
> maybeHead (x:_) = Just x
> 
> and it evaluates fine. But this
> 
> maybeHead [1,2,3]
> 
> produces error:
> :     • No instance for (Show (MyMaybe Integer))
> :         arising from a use of ‘show’
> :     • In the expression: show (maybeHead [1, 2, 3])
> :       In an equation for ‘it’: it = show (maybeHead [1, 2, 3])

    data MyMaybe a = Jus a | Not
            deriving (Show, Eq)

Your text should have introduced to/warned you about deriving and
typeclasses.


------------------------------

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 3
*****************************************

Reply via email to