[Haskell-cafe] |> vs. $ (was: request for code review)

Brian Hulley brianh at metamilk.com
Mon Mar 6 15:43:41 EST 2006

Shannon -jj Behrens wrote:
> I find "ctx |> currTok |> tokenType" to be more readable than
> "tokenType $ currTok $ ctx" because you're not reading the code in
> reverse.  That's my primary complaint with "." and "$".  That's
> especially the case when I'm spreading the code over multiple lines:
> -- Translate a C type declaration into English.
> translate :: String -> String
> translate s =
>   s |>
>   createParseContext |>
>   readToFirstIdentifier |>
>   dealWithDeclarator |>
>   consolidateOutput

If you were wanting to be able to deal with exceptions/ errors etc during 
the translation process, you'd usually use a monad (Haskell's version of a 
pipe), in which case the operations could still be read left to right eg:

translate :: (Monad m) => String -> m String
translate = do

So while . and $ are useful for combining functions together in parts of a 
program, and are consistent with the idea that the function always comes 
first followed by its argument, the top level (at least) would usually be 
monadic and hence not require |> to get left-to-right readability. I've 
copied the links on monads below from a previous post by Jared:


Regards, Brian. 

More information about the Haskell-Cafe mailing list