hawk
hawk copied to clipboard
auto-lambda
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
> printf "1\t2" | hsl '(x,y) -> (y,x)'
Wait... This works?
No, it doesn't, I forgot a lambda (fixed now). Or are you surprised because the types are ambiguous?
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.