[Haskell-cafe] |> vs. $ (was: request for code review)
Shannon -jj Behrens
jjinux at gmail.com
Mon Mar 6 14:25:49 EST 2006
By the way, thanks for everyone's comments so far! They're very helpful!
> Also, most haskell programs use $ instead of |>
>
> > -- For convenience:
> > currTokType :: ParseContext -> TokenType
> > currTokType ctx = ctx |> currTok |> tokenType
>
> this could be written as:
> tokenType $ currTok $ ctx
Concerning:
-- |> is like a UNIX pipe.
infixl 9 |>
x |> f = f x
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
I prefer |> for readability, but I understand that it can be bad to
spring new constructs on programmers in the middle of a program, and
I'm totally in favor of following standard Haskell idioms. Does
anyone else have strong opinions one way or the other? It seems like
most of my program is centered around pipes of "|>", so it's an
important issue.
Thanks!
-jj
More information about the Haskell-Cafe
mailing list