23 Aug 11:23 2013

## typeclass constraints

TP <paratribulations <at> free.fr>

2013-08-23 09:23:24 GMT

2013-08-23 09:23:24 GMT

Hi everybody, There is something I do not understand in the way typeclass constraints are inferred. 1/ Take the following function definition: sum' [] = [] sum' (x:xs) = x + sum' xs GHCI correctly gives: > :t sum' sum' :: Num [a] => [[a]] -> [a] So it has inferred that the type list has to be an instance of Num for sum' to be able to work. It will give an error if we try to use sum' without implementing the instance. 2/ Now, take the following definition: ------------------------ {-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH import Language.Haskell.TH.Syntax p :: a -> ExpQ p n = [| show n |] ------------------------(Continue reading)