[Haskell-beginners] Custom type classes

Daniel Hinojosa dhinojosa at evolutionnext.com
Mon Jan 25 08:08:10 UTC 2016


Ah. I had a suspicion it had to do with extensions. Got to study up on it.
Thanks
On Jan 25, 2016 12:42 AM, "Imants Cekusins" <imantc at gmail.com> wrote:

> Hello Daniel,
>
> it works with these tweaks:
>
> -- begin
>
> {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-}
> module TupInst where
>
>
> data Tuple3 a b c = Tuple3 a b c deriving (Show)
>
> data Tuple2 a b = Tuple2 a b deriving (Show)
>
> class Indexable idx a where
>    first :: idx -> a
>
>
> instance Indexable (Tuple2 a b) a where
>    first (Tuple2 a0 b0) = a0
>
>
> instance Indexable (Tuple3 a b c) a where
>    first (Tuple3 a0 b0 c0) = a0
>
> -- end
>
> call it in ghci like this:
>
> first $ Tuple3 (1::Int) 'a' False::Int
> _______________________________________________
> 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/20160125/8ca3a761/attachment.html>


More information about the Beginners mailing list