Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Hutton Ex 8.9.7 (trent shipley)
2. Re: Hutton Ex 8.9.7 (Tobias Brandt)
----------------------------------------------------------------------
Message: 1
Date: Sat, 15 Sep 2018 01:23:47 -0700
From: trent shipley <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] Hutton Ex 8.9.7
Message-ID:
<caeflybjfhgyferk-aj9fs3j9qttq_znh7tyqrx29w3zzcob...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I couldn't get close on my own.
From: https://github.com/pankajgodbole/hutton/blob/master/exercises.hs
{-
7. Complete the following instance declarations:
instance Eq a => Eq (Maybe a) where
...
instance Eq a => Eq [a] where
...
-}
-- suggested answer
instance Eq a => Eq (Maybe a) where
-- Defines the (==) operation.
Nothing == Nothing = True
Just == Just = True
-- why isn't this Just a == Just a ?
-- My guess is that a and Just a are different types and can't be ==
in Haskell
_ == _ = False
instance Eq a => Eq [a] where
-- Defines the (==) operation.
[] == [] = True
[x] == [y] = x == y
(x:xs) == (y:ys) = x==y && xs==ys -- I assume this is implicitly
recursive.
_ == _ = False
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180915/6330b28a/attachment-0001.html>
------------------------------
Message: 2
Date: Sat, 15 Sep 2018 11:17:54 +0200
From: Tobias Brandt <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Hutton Ex 8.9.7
Message-ID:
<20180915111754.horde.sccvnmtf7yurt8phlmj0...@webmail.uni-bremen.de>
Content-Type: text/plain; charset="utf-8"; Format="flowed";
DelSp="Yes"
Hey,
a few notes:
1. The (==) function in the second equation of the Maybe instance of
(==) is not complete yet, since you need to match on instances of the
Maybe type and "Just :: a -> Maybe a". Your idea "Just a == Just a"
goes in the right direction, but please note that you can't bind two
variable names ("a") in the same equation. You need to give each
"boxed value" a different name. I'm sure you can work it out from there.
2. The right hand side of "(x:xs) == (y:ys)" is not implicitly
recursive, but rather explicitly! Since we apply the function (==) to
the smaller lists "xs" and "ys" until we arrive at a base case.
Greetings,
Tobias
----- Nachricht von trent shipley <[email protected]> ---------
Datum: Sat, 15 Sep 2018 01:23:47 -0700
Von: trent shipley <[email protected]>
Antwort an: The Haskell-Beginners Mailing List - Discussion of
primarily beginner-level topics related to Haskell
<[email protected]>
Betreff: [Haskell-beginners] Hutton Ex 8.9.7
An: Haskell Beginners <[email protected]>
> I couldn't get close on my own.
> From: https://github.com/pankajgodbole/hutton/blob/master/exercises.hs
>
> {-
> 7. Complete the following instance declarations:
> instance Eq a => Eq (Maybe a) where
> ...
>
> instance Eq a => Eq [a] where
> ...
> -}
> -- suggested answer
>
> instance Eq a => Eq (Maybe a) where
> -- Defines the (==) operation.
> Nothing == Nothing = True
> Just == Just = True
> -- why isn't this Just a == Just a ?
> -- My guess is that a and Just a are different types and
> can't be == in Haskell
> _ == _ = False
>
> instance Eq a => Eq [a] where
> -- Defines the (==) operation.
> [] == [] = True
> [x] == [y] = x == y
> (x:xs) == (y:ys) = x==y && xs==ys -- I assume this is
> implicitly recursive.
> _ == _ = False
>
>
>
----- Ende der Nachricht von trent shipley <[email protected]> -----
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180915/a5bd4716/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 123, Issue 6
*****************************************