articles icon indicating copy to clipboard operation
articles copied to clipboard

fbut: (\p1 p2 -> e) is not (\p1 -> \p2 -> e)

Open hasufell opened this issue 7 years ago • 2 comments
trafficstars

You can see the discussion at http://tunes.org/~nef/logs/haskell/18.04.29 at around time 09:13:30

This aligns with the report: https://www.haskell.org/onlinereport/haskell2010/haskellch3.html (section 3.3 Curried Applications and Lambda Abstractions), where for patterns, it desugars as such:

\ p1 … pn -> e = \x1 … xn -> case (x1, …, xn) of (p1, …, pn) -> e

Example

pattern matching sugar

-- evaluates to 1
let f = \(Just a) b -> a + b in (f undefined) `seq` 1
-- exception Prelude.undefined
let f = \(Just a) -> \b -> a + b in (f undefined) `seq` 1

desugared versions

-- evaluates to 1
let f = \a -> \b -> case (a, b) of (Just x, y) -> x + y in (f undefined) `seq` 1
-- exception Prelude.undefined
let f = \a -> case a of (Just x) -> \b -> x + b in (f undefined) `seq` 1

I'm not sure this qualifies as a frequent thing coming up in #haskell, but it certainly is an oddity.

hasufell avatar Apr 29 '18 17:04 hasufell

Interesting! Since it’s not actually frequently come up in #haskell, I won’t include it in the list as its own section, which is meant as a hyperlink reference for the channel though. Maybe it can be included in the chapter about f x = is not f = \x -> section though, since it’s probably the same phenomenon?

quchen avatar Apr 29 '18 20:04 quchen

since it’s probably the same phenomenon?

I don't think so. You cannot demonstrate the difference in strictness properties when just comparing with a single function argument. For one argument, the case-of expression will be pretty much the same.

Another way of expressing it:

-- the following is only true if x and y are not patterns
\x y -> e = \x -> \y -> e

hasufell avatar Apr 29 '18 22:04 hasufell

Cleaning up old open issues/discussions.

quchen avatar Jul 12 '23 09:07 quchen