Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Brian Hulley
Benjamin Franksen wrote: On Tuesday 23 May 2006 02:00, Brian Hulley wrote: I wonder if Haskell' will automatically make type variables scope over the function body (without an explicit forall)? Is there any reason why they shouldn't always do so? One I can think of is that the type signature f

Re[2]: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Bulat Ziganshin
Hello Jacques, Tuesday, May 23, 2006, 7:13:33 PM, you wrote: malloc :: Storable a => IO (Ptr a) malloc = doMalloc undefined where doMalloc :: Storable b => b -> IO (Ptr b) doMalloc dummy = mallocBytes (sizeOf dummy) >>>Is there any reason to not code this as >>> >>

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Robert Dockins
On May 23, 2006, at 11:13 AM, Jacques Carette wrote: Bertram Felgenhauer wrote: Jacques Carette wrote: Bulat Ziganshin wrote: malloc :: Storable a => IO (Ptr a) malloc = doMalloc undefined where doMalloc :: Storable b => b -> IO (Ptr b) doMalloc dummy = mallocBytes (sizeOf dumm

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Udo Stenzel
Jacques Carette wrote: > Bulat Ziganshin wrote: > > >malloc :: Storable a => IO (Ptr a) > >malloc = doMalloc undefined > > where > > doMalloc :: Storable b => b -> IO (Ptr b) > > doMalloc dummy = mallocBytes (sizeOf dummy) > > > > > Is there any reason to not code this as > > malloc

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Brian Hulley
Jacques Carette wrote: I guess I prefer a type annotation over a dummy function that is there just to force the type checker to believe me. If one has to force the type checker, may as well do it with a type, not code! I agree totally. Also, I think there is a more general issue regarding the

Re[2]: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Bulat Ziganshin
Hello Brian, Tuesday, May 23, 2006, 7:10:23 PM, you wrote: > Yes. The supreme clevernesss of Bulat's trick is that doMalloc unifies the my main trick is that i read sources of std libs :) -- Best regards, Bulatmailto:[EMAIL PROTECTED]

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Jacques Carette
Bertram Felgenhauer wrote: Jacques Carette wrote: Bulat Ziganshin wrote: malloc :: Storable a => IO (Ptr a) malloc = doMalloc undefined where doMalloc :: Storable b => b -> IO (Ptr b) doMalloc dummy = mallocBytes (sizeOf dummy) Is there any reason to not code this

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Brian Hulley
Jacques Carette wrote: Bulat Ziganshin wrote: malloc :: Storable a => IO (Ptr a) malloc = doMalloc undefined where doMalloc :: Storable b => b -> IO (Ptr b) doMalloc dummy = mallocBytes (sizeOf dummy) Is there any reason to not code this as malloc :: Storable a => IO (Ptr a)

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Bertram Felgenhauer
Jacques Carette wrote: > Bulat Ziganshin wrote: > > >malloc :: Storable a => IO (Ptr a) > >malloc = doMalloc undefined > > where > > doMalloc :: Storable b => b -> IO (Ptr b) > > doMalloc dummy = mallocBytes (sizeOf dummy) > > > > > Is there any reason to not code this as > > malloc

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Jacques Carette
Bulat Ziganshin wrote: malloc :: Storable a => IO (Ptr a) malloc = doMalloc undefined where doMalloc :: Storable b => b -> IO (Ptr b) doMalloc dummy = mallocBytes (sizeOf dummy) Is there any reason to not code this as malloc :: Storable a => IO (Ptr a) malloc = mallocBytes $

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Benjamin Franksen
On Tuesday 23 May 2006 02:00, Brian Hulley wrote: > I wonder if Haskell' will automatically make type variables scope > over the function body (without an explicit forall)? Is there any > reason why they shouldn't always do so? One I can think of is that the type signature for a function may be at

Re[2]: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-23 Thread Bulat Ziganshin
Hello Brian, Tuesday, May 23, 2006, 4:05:45 AM, you wrote: > Thanks for the solutions. The GHC scoped typed variables seem to be the best > solution since they would seem to be the only way to implement something > where the type only occurs in the result eg (if the actual fonts were to be > adde

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-22 Thread Brian Hulley
Cale Gibbard wrote: Hello, There's a prelude function called asTypeOf which might help here: asTypeOf :: a -> a -> a asTypeOf = const You can use maxBound `asTypeOf` (fst3 . head $ elements) Another option is GHC's scoped type variables, which you use by adding a type signature to your pattern

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-22 Thread Brian Hulley
Chris Kuklewicz wrote: See "7.4.10.3 Declaration type signatures" in the manual: http://haskell.org/ghc/docs/6.4.2/html/users_guide/type-extensions.html#decl-type-sigs At the moment, the "i" in the type declaration and in the body are not the same "i". To get the "i" from the type declaration f

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-22 Thread Cale Gibbard
Hello, There's a prelude function called asTypeOf which might help here: asTypeOf :: a -> a -> a asTypeOf = const You can use maxBound `asTypeOf` (fst3 . head $ elements) Another option is GHC's scoped type variables, which you use by adding a type signature to your pattern. See: http://www.has

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-22 Thread Chris Kuklewicz
See "7.4.10.3 Declaration type signatures" in the manual: http://haskell.org/ghc/docs/6.4.2/html/users_guide/type-extensions.html#decl-type-sigs At the moment, the "i" in the type declaration and in the body are not the same "i". To get the "i" from the type declaration for createMonoMultiFont i

Re: [Haskell-cafe] Problem trying to get class Bounded to work

2006-05-22 Thread Brian Hulley
Brian Hulley wrote: Hi - I've got the following function which doesn't compile: createMonoMultiFont :: (MonadException m, Enum i, Bounded i) => [(i, Font, Colour)] -> m (MonoMultiFont i) createMonoMultiFont elements = liftIO . block $ do mmfRaw <- duma_MonoMultiFont_cr

[Haskell-cafe] Problem trying to get class Bounded to work

2006-05-22 Thread Brian Hulley
Hi - I've got the following function which doesn't compile: createMonoMultiFont :: (MonadException m, Enum i, Bounded i) => [(i, Font, Colour)] -> m (MonoMultiFont i) createMonoMultiFont elements = liftIO . block $ do mmfRaw <- duma_MonoMultiFont_create (fromEnum (maxBo