[Haskell-beginners] instance 2

Ut Primum utprimum at gmail.com
Wed Apr 22 19:49:46 UTC 2020


Hi,

I think the problem is indentation. Write the code this way:

data StringOrInt = TisanInt Integer | TisAString String

instance Eq (StringOrInt) where
  (==) (TisanInt v) (TisanInt v') = v == v'
  (==) (TisAString s) (TisAString s') = s==s'

where the red lines are indented (it means you have to leave two white
spaces at the beginning of those lines).

Ut

Il giorno mer 22 apr 2020 alle ore 21:14 Alexander Chen <
alexander at chenjia.nl> ha scritto:

> hi,
>
> *data StringOrInt = TisanInt Int | TisAString String*
>
> *instance Eq (StringOrInt) where *
> *(==) (TisanInt v) (TisanInt v') = v == v'*
> *(==) (TisAString s) (TisAString s') = s == s'*
>
>
> *prelude>*
>
> *Instance_testen.hs:4:37: error:*
> *    Ambiguous occurrence ‘==’*
> *    It could refer to either ‘Prelude.==’,*
> *                             imported from ‘Prelude’ at
> Instance_testen.hs:1:1*
> *                             (and originally defined in ‘GHC.Classes’)*
> *                          or ‘Main.==’, defined at Instance_testen.hs:4:1*
> *  |*
> *4 | (==) (TisanInt v) (TisanInt v') = v == v'   |
>              ^^*
>
> *Instance_testen.hs:5:41: error:*
> *    Ambiguous occurrence ‘==’*
> *    It could refer to either ‘Prelude.==’,*
> *                             imported from ‘Prelude’ at
> Instance_testen.hs:1:1*
> *                             (and originally defined in ‘GHC.Classes’)*
> *                          or ‘Main.==’, defined at Instance_testen.hs:4:1*
> *  |*
> *5 | (==) (TisAString s) (TisAString s') = s == s' *
> *  |                                         ^^*
> *[1 of 1] Compiling Main             ( Instance_testen.hs, interpreted )*
> *Failed, no modules loaded.*
>
>
>
> *what gives?*
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200422/4c7a99b6/attachment.html>


More information about the Beginners mailing list