[Haskell-cafe] A pattern type signature cannot bind scoped type variables `t'

George Pollard porges at porg.es
Thu Jan 22 03:50:47 EST 2009


On Mon, 2009-01-12 at 20:24 -0200, rodrigo.bonifacio wrote:
> Hi all,
> 
> I'm trying to build a library that has the following code:
> 
> hasTypeOf (TermRep (dx,_,_)) (x::t)
> = ((fromDynamic dx)::Maybe t)
> 
Could you do something like this?

Enforce the types with a signature:

hasTypeOf :: (Typeable t) => Dynamic -> t -> Maybe t
hasTypeOf x _ = fromDynamic x

> hasTypeOf (toDyn (2::Int)) (undefined::Integer)
Nothing
> hasTypeOf (toDyn (2::Int)) (undefined::Int)
Just 2

Or if you just want boolean result:

hasTypeOf x y = typeOf y == dynTypeRep x
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rcmAttmntN3MDzg
Type: micalg/pgp-sha1
Size: 0 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090122/7d43be38/rcmAttmntN3MDzg-0001.bin


More information about the Haskell-Cafe mailing list