4 ms·
Minor nitpick. Technically, this: #(->> % (drop 3) (filter p) (take 5)) Is equivalent to: take 5 . filter p . drop 3
by catnaroek 11y ago
Minor nitpick. Technically, this:
#(->> % (drop 3) (filter p) (take 5))
Is equivalent to:
take 5 . filter p . drop 3
- fnordsensei 11y agoIs take 5 . filter p . drop 3 An anonymous function call in Haskell? I don't know the language (although it's on my to-learn sequence).
- catnaroek 11y agoIt's an anonymous function, which it not being called.
- deleted 11y ago[deleted]
- catnaroek 11y agoYou probably meant to reply to mietek.
- mietek 11y agoYes, written in pointless style. You could make it less pointless by replacing the (.)s with a point. \xs -> take 5 (filter p (drop 3 xs)) https://wiki.haskell.org/Pointfree https://wiki.haskell.org/Pointfree
- marcosdumay 11y agoYes. It's three anonymous ("take 5", "filter p" and "drop 3") functions composed by the "." operator, creating another anonymous function. One of the types, for example: take :: Int -> [a] -> [a] What means a function that takes an Int argument and returns another function, that takes a list and returns a list of the same type.
- pja 11y agoghci will (usually) tell you: phil@arod:~$ ghci GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :t take 5 . filter (\ _ -> True) . drop 3 take 5 . filter (\ _ -> True) . drop 3 :: [a] -> [a] So it’s a function from List of a to List of a
- deleted 11y ago[deleted]
- takle 11y agoOne could also change the Haskell. Data.Function (&); Control.Arrow (>>>) -- the pipe operator seems to be all the rage these days (|>) = (&) -- forward application + forward composition xs |> (drop 3 >>> filter p >>> take 5) Only function application xs |> drop 3 |> filter p |> take 5
- catnaroek 11y agoI never understood the appeal of the pipe operator. It's a kludge to work around the need to eta-expand chained function compositions, which in turn is a kludge to work around the value restriction, which in turn is a kludge to prevent the combination of polymorphism and storage effects from breaking type soundness. Haskell doesn't need any of this.
- takle 11y agoI agree with you. I'm going to write a post about function application and composition (right-to-left / left-to-right) so other communities can stop discussing non-essential matters. I do like the fact that the `pipe operator` is often mentioned along the bash '|' which is used in a pointfree style. Well it might make sense sometimes, so its good to know one's options :) p x y z = f (g x y) z p = ((.) f) . g