ninesalt
ninesalt

Reputation: 4354

Unresolved overloading error in Haskell

getNext a = if even a then a/2 else (3*a)+1 

for some reason this line of code returns an unresolved overloading error.

Main> getNext 13
ERROR - Unresolved overloading
*** Type       : (Fractional a, Integral a) => a

What am I doing wrong or what am I missing? I haven't used Haskell in quite some time so I might have forgotten a few things.

Upvotes: 4

Views: 896

Answers (1)

psmears
psmears

Reputation: 28040

You probably want

a `div` 2

rather than

a/2

The error is happening because even a implies that a is an integer, but the use of the non-integer division operator / implies otherwise.

Upvotes: 7

Related Questions