Thursday, 15 May 2014

haskell - Type Class Data Types -



haskell - Type Class Data Types -

having read article scrap type classes, re-implemented of ideas shown. while doing came across strange: type class - type can used type constraint! question: why that?

my code:

{-# language rank2types #-} info ifunctor f = ifunctor { _fmap :: forall b. (a -> b) -> f -> f b } -- type checks... _fmap2 :: ifunctor f => (a -> b) -> f (f a) -> f (f b) _fmap2 = \inst -> _fmap inst . _fmap inst

in ghci next thing happens:

>>> :t _fmap2 :: ifunctor f => (a -> b) -> f (f a) -> f (f b) _fmap2 :: ifunctor f => (a -> b) -> f (f a) -> f (f b) :: ifunctor f -> (a -> b) -> f (f a) -> f (f b)

this doesn't work on ghc 7.8.2. gives error expected constraint, ‘ifunctor f’ has kind ‘*’.

older versions of ghc had bug allowed => used -> in situations. because internally type class constraints passed arguments in form of method dictionaries.

haskell types typeclass

No comments:

Post a Comment