fork download
  1. infixr 5 :::
  2. data List a b = (:::) a b | Nil deriving (Eq, Show)
  3.  
  4. nil = Nil :: List () ()
  5.  
  6. dot :: Num a => List a b -> List a b -> a
  7. Nil `dot` Nil = 0
  8. (x ::: xs) `dot` (y ::: ys) = x * y + xs `dot` ys
  9.  
  10. test :: Integer -> Integer -> List Integer a -> List Integer a -> Integer
  11. test 0 _ a b = a `dot` b
  12. test n i a b = test (n - 1) (i + 1) (2*i+1 ::: a) (i*i ::: b)
  13. --test n i a b = test (n - 1) (i + 1) a (i*i ::: b)
  14.  
  15. main = do
  16. let n = 5
  17. print $ 1 ::: 2 ::: 3 ::: nil
  18. print $ test n 0 nil nil
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:8:38:
    Couldn't match expected type `List a b' against inferred type `b1'
      `b1' is a rigid type variable bound by
           the type signature for `dot' at prog.hs:6:23
    In the first argument of `dot', namely `xs'
    In the second argument of `(+)', namely `xs `dot` ys'
    In the expression: x * y + xs `dot` ys

prog.hs:18:21:
    Couldn't match expected type `Integer' against inferred type `()'
      Expected type: List Integer a
      Inferred type: List () ()
    In the third argument of `test', namely `nil'
    In the second argument of `($)', namely `test n 0 nil nil'
stdout
Standard output is empty