[Haskell-cafe] checking types with type families
daniel.is.fischer at web.de
Wed Jun 23 00:21:18 EDT 2010
On Wednesday 23 June 2010 05:46:46, Evan Laforge wrote:
> I have a parameterized data type:
> > data Val result = VNum Double | VThunk (SomeMonad result)
> > type Environ result = Map Symbol (Val result)
> I have a class to make it easier to typecheck Vals:
> > class Typecheck a where
> > from_val :: Val result -> Maybe a
Would it work if you made Typecheck a two-parameter type class?
class Typecheck result a where
from_val :: Val result -> Maybe a
instance Typecheck result Double where ...
instance Typecheck result (SomeMonad result) where
> > instance Typecheck Double where
> > from_val (VNum d) = Just d
> > from_val _ = Nothing
> Now I can write
> > lookup_environ :: (Typecheck a) => Symbol -> Environ result -> Maybe a
> Now of course there's a question of how to write Typecheck for VThunk.
> I would like to be able to call 'lookup_environ' expecting a
> 'SomeMonad result' and get Nothing or Just depending on if it's
> > instance Typecheck (SomeMonad result) where
> > from_val (VThunk f) = Just f
> But I need something to say that the 'result' from the instance head
> is the same as the 'result' from the class declaration, because
> otherwise I get
> Couldn't match expected type `result'
> against inferred type `result1'
More information about the Haskell-Cafe