lundi 8 avril 2019

Haskell compare two int with if statement

I want to implement a function named log2, which computes the integer log (base 2) of its argument. I can't use log function. My solution is: to check if x equals to 2^y. If x equals 2^y give the value y, if x doesn't equals to 2^y then y = y + 1. This will go on until y is found. This is what I got so far:

log2 x = y where y = 0
    if x == 2^y then y
    else y = y + 1

When I want to run this I will get this error:

error: parse error on input `if'

I am new to Haskell so can somebody explain me what's wrong?

Aucun commentaire:

Enregistrer un commentaire