
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?

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@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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (2)
-
Alexander Chen
-
Ut Primum