[Haskell-cafe] a simpler way to declare typeclass instances
MigMit
miguelimo38 at yandex.ru
Sat Oct 25 15:50:52 UTC 2014
Well, in this case it would look like a definition of a completely independent function (=), which, obviously, clashes with the already defined one.
In general, it's a good idea to keep things that don't make sense without some previous declaration inside the block, established by that declaration.
> On 25 Oct 2014, at 19:42, Alexey Muranov <alexey.muranov at gmail.com> wrote:
>
> Hello,
>
> i am trying to understand how typeclasses work. I know that they can be used as follows (from the manual):
>
> data Foo = Foo {x :: Integer, str :: String}
>
> instance Eq Foo where
> (Foo x1 str1) == (Foo x2 str2) = (x1 == x2) && (str1 == str2)
>
> I am wondering, why is the following seemingly unambiguous syntax not allowed too?
>
> data Foo = Foo { x :: Integer, str :: String }
>
> instance Eq Foo
>
> (Foo x1 str1) == (Foo x2 str2) = (x1 == x2) && (str1 == str2)
>
> If it was allowed, it seems that it could also be applied to records:
>
> class HasName r where
> name :: r -> String
>
> data Bird = Bird { name :: String, wingNumber :: Integer }
> data Person = Person { name :: String, likesBirds :: Bool }
>
> instance HasName Bird
> instance HasName Person
>
> Alexey.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list