
On 27/10/2010 08:12, Bas van Dijk wrote:
On Wed, Oct 27, 2010 at 8:09 AM, Isaac Dupree
wrote: On 10/27/10 01:51, Bas van Dijk wrote:
On Tue, Oct 26, 2010 at 9:09 PM, Henning Thielemann
wrote: On Tue, 26 Oct 2010, Bas van Dijk wrote:
malloc :: forall a. Storable a => IO (Ptr a) malloc = mallocBytes (untag (sizeOf :: SizeOf a))
(Note that this does require the ScopedTypeVariables language extension.)
Haskell 98 solution would be nicer. Something like
malloc :: Storable a => IO (Ptr a) malloc =
let aux :: Storable a => SizeOf a -> IO (Ptr a) aux = mallocBytes . untag in aux sizeOf
Great! It's nice to know that this proposal doesn't require ScopedTypeVariables.
It may not *require* it, but the code using ScopedTypeVariables is far more readable than that Haskell98/Haskell2010 code (though, perhaps we can improve on its readability a bit).
Indeed. My patches for base and the other packages uses ScopedTypeVariables extensively. It makes code shorter and easier to read.
Note that the original version is shorter and easier to read if you use ScopedTypeVariables too. We deliberately avoided ScopedTypeVariables in that code in order to make it compatible with Haskell 98.
Is using ScopedTypeVariables a problem by the way? Should base use Haskell2010 exclusively or are extensions allowed?
(ScopedTypeVariables is not in Haskell2010, according to http://www.haskell.org/onlinereport/haskell2010/haskellli2.html#x3-5000 )
I hope they will be in Haskell2011.
Highly unlikely. ScopedTypeVariables is a big extension with room for alternative designs, it will take a lot of effort to get it into the language standard. It depends on ExplicitForall for one thing, which still isn't in the language and that's fairly straightforward. Cheers, Simon