haskell

Haskell Illegal term-level use of the type constructor 'Int'


I'm very new to Haskell and am trying to multiply a number by itself as followed:

Test :: Int -> Int
Test = Int * Int

Doing this gave me the following error ' Illegal term-level use of the type constructor ‘Int’' In the first argument of ‘(*)’, namely ‘Int’ In the expression: Int * Int In an equation for 'Test': Test = Int * Int

I'm pretty confused from this message. Can anyone explain what went wrong with this implementation?


Solution

  • Int is a type, not a value or expression.

    Also note that by convention, tokens starting with an uppercase denote a type, typeclass, or type constructor. For functions, you want to start with a lower case.

    test :: Int -> Int
    test n = n * n
    

    If you're in need of a haskell resource, I strongly suggest reading Learn You a Haskell. It covers all these basics and more.