Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm returning integer instead of Bool, compiler bug?

Function signature clearly states that it should return a Bool so why is the function returning 96? What is more, compiler thinks that 96 is actually a Bool. Is this a bug?

> isLeapYear year =\
|       (modBy 4 year == 0) && (modBy 100 year /= 0) || (modBy 400 year == 0)
<function> : Int -> Bool

> isLeapYear 1996
96 : Bool

It seems to work sometimes though:

> isLeapYear 2000
True : Bool
> isLeapYear 1800
False : Bool
like image 571
frost Avatar asked Mar 04 '23 14:03

frost


1 Answers

This is a compiler bug which I filed last year and which has now been fixed.

It affects only the /= operator when one argument is 0: replacing (modBy 100 year /= 0) with (not (modBy 100 year == 0)) will work around the problem.

The bug has been fixed in the source repository, but I don't know when the fix will be released.

like image 60
Luke Woodward Avatar answered Mar 11 '23 04:03

Luke Woodward