[Haskell-cafe] Newbie question related to list evaluation

Felipe Lessa felipe.lessa at gmail.com
Sun Jan 6 13:45:48 EST 2008


On Jan 6, 2008 4:40 PM, Jonathan Cast <jonathanccast at fastmail.fm> wrote:
> let is always recursive in Haskell, so this is a recursive definition
> of pos.  To break the recursion, use
>
>
> matchReverse (x:xs) (y:ys) pos = let (matched, pos') = matchReverse
> xs ys (pos + 1)
>                                   in if matched then ((x==y), pos')
>                                                else (False, pos')

Actually, I think he meant

matchReverse (x:xs) (y:ys) pos =
        let (matched, pos') = matchReverse xs ys (pos + 1)
        in if matched then ((x==y), pos) else (False, pos')

As as side note, GHC's flag -Wall would have warned about creating a
variable with a name already in scope.

-- 
Felipe.


More information about the Haskell-Cafe mailing list