What does the : infix operator do in Haskell?

后端 未结 4 1786
甜味超标
甜味超标 2020-12-03 00:45

I\'m reading A Gentle Introduction to Haskell (which is not so gentle) and it repeatedly uses the : operator without directly explaining what it does.

S

4条回答
  •  渐次进展
    2020-12-03 01:22

    Could always check out the types in GHCi/HUGS, as the first steps in the tutorial encourage you to download GHC/HUGS.

    Prelude> :t (:)
    (:) :: a -> [a] -> [a]
    Prelude> :t (++)
    (++) :: [a] -> [a] -> [a]
    

    From their respective types, it's quite easy to deduce their usage.

    PS: http://haskell.org/hoogle/ is awesome.

提交回复
热议问题