Skip to content

Instantly share code, notes, and snippets.

@HirotoShioi
Last active January 7, 2018 13:54
Show Gist options
  • Save HirotoShioi/26c6dd1072578878b45d9d12f0b15d4a to your computer and use it in GitHub Desktop.
Save HirotoShioi/26c6dd1072578878b45d9d12f0b15d4a to your computer and use it in GitHub Desktop.
Haskellにおける型クラス制約の役割 ref: https://qiita.com/HirotoShioi/items/5474119ba3682448c109
• No instance for (Num a) arising from a use of ‘+’
Possible fix:
add (Num a) to the context of
the type signature for:
sum' :: forall a. [a] -> a
• In the expression: x + acc
In the first argument of ‘foldl1’, namely ‘(\ x acc -> x + acc)’
In the expression: foldl1 (\ x acc -> x + acc)
|
5 | sum' = foldl1 (\x acc -> x + acc)
|
*Main> sum' [1,2,3,4,5]
15
sum' :: (Num a) => [a] -> a
sum' = foldr1 (\x acc -> x + acc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment