3 Nov 20:30 2002

## getting the right types

Hal Daume III <hdaume <at> ISI.EDU>

2002-11-03 19:30:52 GMT

2002-11-03 19:30:52 GMT

Hi all, I have a function which essentially looks like this: f my_data = do a1 <- newArray ... ... a2 <- newArray ... g my_data a1 a2 where f is a monadic operation essentially of type 'a -> m a'. The problem is that when this function isn't given a type signature, you get something like: f :: (MArray a1 p e, MArray a2 p e) => t where a1 and a2 aren't bound in t. Now, I could provide a type signature on the array expressions, something like: ... (a1 :: IOArray Int Int) <- newArray ... but i would like to be able to use unboxed arrays when possible, and i don't want to bind the funtion to be in IO. My current solution is to define: data ArrayType arr prob = forall ix . ArrayType (arr ix prob) asArray :: arr ix prob -> ArrayType arr prob -> arr ix prob a `asArray` _ = a Sort of like asTypeOf. Then, I change f to:(Continue reading)