instance 2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

instance 2

Alexander Chen
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: instance 2

Ut Primum
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 <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners