Be cautious of upper/lower case letters about function in Haskell

As a layman of Haskell, I find being cautious of upper/lower case letters help me a lot to get understanding of functions:

(1) Function name doesn’t begin upper case: it can be lower case (e.g., sqrt) or special characters (e.g., +).

(2) Function has type. Let’s define a new function, incInt:

incInt :: Integer -> Integer
incInt a = a + 1

The above identifies incInt‘s type is “Integer -> Integer“: Integer is type in Haskell, and types begin with upper case. Check another built-in functionsqrt:

Prelude> :t sqrt
sqrt :: Floating a => a -> a

The “Floating a” which is in the left of => is called type constraint: Floating is typeclass, and its values are types which satisfy this typeclass (Floatingtypeclass contains both Float and Double types); a is a type variable which can be any type which belongs to Floating typeclass.

Takeaway:
a) Function name can’t begin with upper case letters.
b) Type, typeclass, type variable occur in function type definition. Type and typeclass begin with upper case letters, and type variable need to begin with lower case letters.

5 thoughts on “Be cautious of upper/lower case letters about function in Haskell”

  1. What is the article about? About function names in lowercase?
    Useless, because these two obvious points can be find in any Haskell book for beginners.

  2. I agree with Haskell beginer. Your title makes it sound like this is a common pitfall. This is an extremely beginner topic, there’s nothing to beware of here.

    I’m struggling to understand why this was linked from Haskell Weekly, where I get my Haskell news. How is this news to anyone but non-Haskell users?

    1. Thanks for your comments! I have written in my article that this is just a summary for myself and I am a layman.

      I don’t know how it is linked from Haskell weekly, and you should contact the owner of Haskell weekly.

  3. Thanks for taking the time to write this up! Haskell has a fairly intimidating reputation, and it can be difficult to find solid, introductory content. Posts like this help change that, which improves the community overall. I hope you continue to share your learning path in the open—it’s definitely not “too simple” 🙂

Leave a Reply to nanxiao Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.