Skip to content

Instantly share code, notes, and snippets.

@duane
Created November 16, 2011 19:43
Show Gist options
  • Save duane/1371111 to your computer and use it in GitHub Desktop.
Save duane/1371111 to your computer and use it in GitHub Desktop.
Type error in small haskell program
module Main where
import Graphics.Sketch
import Data.Array.Repa
import Data.Word
import Control.Monad
import System.Random
randomWord8 :: IO Word8
randomWord8 = getStdRandom random
randomListOfSize :: Int -> IO [Word8]
randomListOfSize 0 = return []
randomListOfSize size = do
xs <- randomListOfSize $ size - 1
x <- randomWord8
return (x:xs)
randomRepaVectorOfSize :: (Shape sh) => Int -> IO (Array sh Word8)
randomRepaVectorOfSize size = liftM (fromList (Z :. size)) randomListOfSize size
@duane
Copy link
Author

duane commented Nov 16, 2011

Error:

test.hs:21:38:
        Couldn't match expected type `IO (Array sh Word8)'
                     with actual type `Array sh0 a0'
         Expected type: [a0] -> IO (Array sh Word8)
           Actual type: [a0] -> Array sh0 a0
         In the return type of a call of `fromList'
         In the first argument of `liftM', namely `(fromList (Z :. size))'

@duane
Copy link
Author

duane commented Nov 16, 2011

test.hs:21:48:
    Could not deduce (sh ~ (Z :. Int))
    from the context (Shape sh)
      bound by the type signature for
                 randomRepaVectorOfSize :: Shape sh => Int -> IO (Array sh Word8)
      at test.hs:21:1-89
      `sh' is a rigid type variable bound by
           the type signature for
             randomRepaVectorOfSize :: Shape sh => Int -> IO (Array sh Word8)
           at test.hs:21:1
    In the first argument of `fromList', namely `(Z :. (size :: Int))'
    In the first argument of `liftM', namely
      `(fromList (Z :. (size :: Int)))'
    In the expression:
      liftM (fromList (Z :. (size :: Int))) (randomListOfSize size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment