Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 541
ninesalt Avatar asked Mar 16 '23 01:03

ninesalt


1 Answers

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.

like image 155
psmears Avatar answered Mar 17 '23 15:03

psmears