[Haskell-beginners] More Data.Vector fun
Philip Scott
haskell-beginners at foo.me.uk
Thu May 13 17:26:31 EDT 2010
Hey ho,
This should be a quick one, I hope! I am mucking about with the moadic
initialisers for vectors, and am experiencing all kinds of fun. For
example, I think I should be able to make a new vector of, say, 3
thingies* long:
Prelude Data.Vector.Generic.Mutable> new 3
Now of course, poor old haskell does not know what sort of thing I am
going to put in it yet, so it gets a bit cross:
<interactive>:1:0:
Ambiguous type variable `m' in the constraint:
`Control.Monad.Primitive.PrimMonad m'
arising from a use of `new' at <interactive>:1:0-4
Probable fix: add a type signature that fixes these type variable(s)
<interactive>:1:0:
Ambiguous type variables `v', `a' in the constraint:
`MVector v a' arising from a use of `new' at <interactive>:1:0-4
Probable fix: add a type signature that fixes these type variable(s)
Now I have paid very close attention to this 'Probable Fix', but have
not been able to find out precisely how to specify what sort of vector I
would like (I guess this is v..) and am even more boggled by 'm'.. I
guess this is asking what sort of Monad I am going to use to fill it up?
An example would be greatly appreciated.
I find the type of 'new' quite interesting:
new
:: forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, Data.Vector.Generic.Mutable.MVector v a) =>
Int -> m (v (PrimState m) a)
So I did a bit of reading up on exstential types, and I (just about) get
what 'forall' does, however I don't know what the (m :: * -> *) and (v
:: * -> * -> *) bits mean. Just telling me what they are called would
probably be enough to get me googling!
I get the feeling I am a bit out of my depth here, but hey ho, I guess
that's how you learn to swim!
All the best,
Phil
* thingies == things of some type, which doesn't really matter at the
momant.
More information about the Beginners
mailing list