[Haskell-cafe] Recursion in Haskell
mvanier at cs.caltech.edu
Sun Feb 18 22:01:42 EST 2007
Brandon S. Allbery KF8NH wrote:
> On Feb 18, 2007, at 21:44 , Michael Vanier wrote:
>> I think what you're asking here is why you need the parens around
>> (x:y) in the second case. Function application doesn't use parentheses
> Function application never applies to pattern matching.
You're right; I take it back. However, ":" is not an acceptable variable name
as such either:
ghci> let foo x : y = x
<interactive>:1:4: Parse error in pattern
":" needs to be surrounded by parens to be treated as a function; otherwise it's
an operator. OK, we can try:
ghci> let foo x (:) y = x
Constructor `:' should have 2 arguments, but has been given 0
In the pattern: :
In the definition of `foo': foo x : y = x
Bottom line: "foo x:y" is not a valid pattern.
>> The usual answer to this is "category theory" which is an extremely
>> abstract branch of mathematics. But you
> Actually, no; my understanding is that category theory as applied to
> Haskell is a retcon introduced when the notion of monads was imported
> from category theory, and the original theoretical foundation of Haskell
> came from a different branch of mathematics.
Nevertheless, a lot of Haskell papers do refer to category theory, and lambda
calculus can be put into that framework as well, so I don't think my statement
is invalid. But as you say, it's a bit of an after-the-fact realization.
More information about the Haskell-Cafe