[Haskell-beginners] Concrete instance of abstract class
Adrian May
adrian.alexander.may at gmail.com
Thu Jun 6 05:28:21 CEST 2013
Hi Brent,
> I would do this using an associated
> type, like so:
>
> class Turtlish t where
> type TState t :: *
> pic :: t -> Dia
> state :: t -> TState t
> move :: TState t -> t -> t
> (>>>),(+++) :: t -> t -> t
> x >>> y = x +++ move (state x) y
>
>
Bingo. Just what I needed. But is this a Haskellish thing to do or am I
showing my C++ background by even wanting something like this? Anyway, for
the sake of any future googlers, I needed {-# LANGUAGE TypeFamilies #-} and
completed the instance with:
instance Turtlish TurtWorld where
type TState TurtWorld = TurtState
...
Thanks,
Adrian.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130606/cd78ef5b/attachment.htm>
More information about the Beginners
mailing list