vt5491
vt5491

Reputation: 2294

What's wrong with this purescript constructor?

Trying to create a constructor for roman digits:

data RomanDigit a = M | D | C | L | V | I

newRomanDigit :: Int -> RomanDigit 
newRomanDigit 1000 = M 
newRomanDigit 500 = D

gets error message:

in module UserMod
at src\UserMod.purs line 81, column 1 - line 81, column 35


  Could not match kind

    Type

  with kind

    Type -> Type


while checking the kind of Int -> RomanDigit
in value declaration newRomanDigit

What am I doing wrong?

Upvotes: 0

Views: 75

Answers (1)

Fyodor Soikin
Fyodor Soikin

Reputation: 80734

You gave RomanDigit a type parameter a, but haven't specified a value for it in the declaration of newRomanDigit.

The way you declared it, RomanDigit is not a Type. RomanDigit Int is a Type, or RomanDigit String is a Type, or perhaps RomanDigit (Array Boolean) is a Type, but RomanDigit by itself is a not a Type, because it's missing the declared type parameter a. This is what the compiler is telling you.

You need to either remove the parameter, e.g.:

data RomanDigit = M | D | C | L | V | I

Or specify it when using RomanDigit, e.g.:

newRomanDigit :: Int -> RomanDigit Int

Since the parameter is not present in any of the values, I suspect that you didn't really mean to have it there.

Upvotes: 8

Related Questions