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

2009-01-22 Thread George Pollard
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


rcmAttmntN3MDzg
Description: micalg/pgp-sha1
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-01-12 Thread rodrigo.bonifacio
Hi all,
I'm trying to build a library that has the following code:
hasTypeOf (TermRep (dx,_,_)) (x::t) = ((fromDynamic dx)::Maybe t)
 
When I try to compile with ghc-6.8.3 I got the following error:
../../StrategyLib/models/drift-default//TermRep.hs:63:30: A pattern type signature cannot bind scoped type variables `t' unless the pattern has a rigid type context In the pattern: x :: t In the definition of `hasTypeOf': hasTypeOf (TermRep (dx, _, _)) (x :: t) = ((fromDynamic dx) :: Maybe t)
 
How can I solve this problem? Is there any option to ignore this erro when compiling with ghc-6.8.3?
Thanks for any help.
Rodrigo.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe