[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-beginners
Subject: [Haskell-beginners] Re: Why is this type ambiguous?
From: Maurício_CA <mauricio.antunes () gmail ! com>
Date: 2009-10-27 1:34:23
Message-ID: hc5imv$sro$1 () ger ! gmane ! org
[Download RAW message or body]
>> But isn't the type of 'dummy' defined by 'return dummy' beeing
>> a possible return value (and, so, dummy :: b)?
> No. let-bindings are polymorphic, so dummy :: forall a. a
Oh, I once learned that some code of mine didn't work because
lambda bindings are monomorphic. Now I can use it for good.
genericCast :: (Storable a, Storable b) => a -> IO b
genericCast v = return undefined >>= \dummy ->
allocaBytes (max (sizeOf v) (sizeOf dummy)) $ \p ->
poke p v >> if False then return dummy else peek (castPtr p)
In ghci:
> let a = 4 :: WordPtr
> b <- genericCast a :: IO (Ptr ())
> b
0x00000004
Thanks!
Maurício
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic