What does :: (double colon) stand for in Haskell?

后端 未结 3 400
闹比i
闹比i 2020-12-13 17:38

I see and use the :: symbols everywhere but still don\'t know what the :: symbol means when programming in Haskell, e.g.

r         


        
3条回答
  •  感动是毒
    2020-12-13 18:06

    You should read:

    foo :: a 
    

    as "the name foo is a value of type a". When you write:

    run :: a -> b 
    

    this means:

    1. You are declaring the name run.

    2. This name will refer to a value that have type a -> b,

    The type a -> b is the type of a function which takes a value of type a and returns another value of type b.

    You must really learn about types to understand Haskell. The type system is one of the most crucial feature of Haskell, and it's what makes the language so expressive.

提交回复
热议问题