[Haskell-beginners] Help with type declaration using MArray
Daniel Fischer
daniel.is.fischer at googlemail.com
Mon Apr 18 05:00:17 CEST 2011
On Monday 18 April 2011 04:38:17, Perry James wrote:
> Hi all,
>
> I'm working through Brown & Cook's "Monadic Memoization Mixins" and have
> come across some code that I can't get to compile with GHC.
>
> The error I get for
>
> arrayDict :: (*MArray *arr (*Maybe *b) m, *Ix *a, *Ord *a)
> => a -> arr a (*Maybe *b) -> *Dict *a b m
>
> is
> Non type-variable argument
> in the constraint: MArray arr (Maybe b) m
> (Use -XFlexibleContexts to permit this)
> In the type signature for `arrayDict':
> arrayDict :: (MArray arr (Maybe b) m, Ix a, Ord a) =>
> a -> arr a (Maybe b) -> Dict a b m
That's clear enough, I think, you have to enable FlexibleContexts.
(Btw, also NPlusKPatterns for newer GHCs.)
>
> Enabling FlexibleContexts causes other errors. What could be going
> wrong? In case this isn't enough context, I've posted the full source
> code for this section of the paper at
> smipple<http://www.smipple.net/snippet/Perry%20James/Monadic%20Memoizati
> on%20Mixins> .
Simple, lines 80-81:
arrayDict size arr = (check, store) where
check a = if a > size then return Nothing
else return readArray arr a
readArray array index :: monad (Maybe b)
so the return in the else branch shouldn't be. Remove it and it compiles.
>
> Thanks in advance for any help,
> Perry
Cheers,
Daniel
More information about the Beginners
mailing list