Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell
Last active September 10, 2021 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinlacewell/0bd14c3457ee70b6a840149268d0c97f to your computer and use it in GitHub Desktop.
Save dustinlacewell/0bd14c3457ee70b6a840149268d0c97f to your computer and use it in GitHub Desktop.
"the cow ate the grass"
"the cow ate the grass"
app/Main.hs:34:8-15: error:
• Occurs check: cannot construct the
infinite type: a ~ a -> a
Expected type: [a]
Actual type: [a -> a]
• In the expression: map f xs
In the expression:
let
a' = f a b
xs = b : cs
in map f xs
In an equation for ‘map2’:
map2 f (a : b : cs)
= let
a' = f a b
xs = b : cs
in map f xs
• Relevant bindings include
a' :: a (bound at app/Main.hs:32:9)
xs :: [a] (bound at app/Main.hs:33:9)
cs :: [a] (bound at app/Main.hs:31:13)
b :: a (bound at app/Main.hs:31:11)
a :: a (bound at app/Main.hs:31:9)
f :: a -> a -> a (bound at app/Main.hs:31:6)
(Some bindings suppressed; use
-fmax-relevant-binds=N or -fno-max-relevant-binds)
|
34 | in map f xs
| ^^^^^^^^
map2 :: (a -> a -> a) -> [a] -> [a]
map2 f [] = []
map2 f [a] = [a]
map2 f (a:[b]) = [f a b, b]
map2 f (a:b:cs) =
let a' = f a b
xs = b:cs
in map f xs
main :: IO ()
main = do
let s = "the cow ate the grass"
print s
print $ map2 (\c1 c2 -> if c1 `elem` "aeiou" then '!' else c1) s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment