Re:Implement with Types, Not Your Brain
by TheAsprngHacker on Tuesday June 25, 2019 @08:01PM
(#20280572)
Maybe I'm misunderstanding what you're saying, but how on Earth would a function
f :: (a -> b -> c) -> b -> a -> c
result in f (+) 1 2
evaluating to "cookie"
? For one, the types (obviously, to me at least) don't work out.Sounds like you could use some real documentation.
The types tell me that that's not the function in question. Type variables in Haskell mean the caller of the function gets to pick the types. That means the implementation doesn't get to - and the compiler makes sure of it.
You're pattern matching on a number and returning a string. The function might be handed a function and expected to return a file handle for all you know from inside the function.
a, b, and c are generic types. You need to supply an implementation of f that doesn't know anything about a, b, or c. How many such implementations are there? Can you supply at least two, both of which finish running in a finite amount of time and neither of which produces any error?
For one.
Now tell me: are types the best documentation?