hawk icon indicating copy to clipboard operation
hawk copied to clipboard

auto-lambda

Open gelisam opened this issue 11 years ago • 3 comments

Swap can be written as:

> printf "1\t2" | hsl swap

or equivalently

> printf "1\t2" | hsl '\(x,y) -> (y,x)'

With implicit arguments, we should be allowed to write it as:

> printf "1\t2" | hsl '(_2, _1)'

I think it would also be useful to support _0 for the entire argument, for those cases where pointfree style is inconvenient:

> seq 10 | hsl 'take 2 _0 ++ drop (length _0 - 2) _0'
1
2
9
10

gelisam avatar Aug 05 '13 22:08 gelisam

> printf "1\t2" | hsl '(x,y) -> (y,x)'

Wait... This works?

ssadler avatar Aug 06 '13 01:08 ssadler

No, it doesn't, I forgot a lambda (fixed now). Or are you surprised because the types are ambiguous?

gelisam avatar Aug 06 '13 02:08 gelisam

The whole point of my type-inference experiments is to see what I can achieve by modifying the inferred type of expressions before I give them to GHC. In this case, the inferred type of the expression \(x,y) -> (y,x) is (t,t1) -> (t1,t), which is too ambiguous. GHC won't resolve the ambiguity, but we can! I observe this type and change it to (ByteString,ByteString) -> (ByteString,ByteString), which is concrete enough for the typeclasses to decide how to parse the input. I then change it again to [(ByteString, ByteString)] -> [(ByteString, ByteString)] and wrap the entire expression in an fmap.

gelisam avatar Aug 06 '13 02:08 gelisam