Вопрос

I must miss something but I can't see why this contrived example doesn't work:

test1 :: Int
test1 = let g = \s -> s + s
            f = \u -> let h = \t -> t + t
                          h' = \v -> v + v
                      in  g (h (h' u))
        in f 1

ghci > parse error on input `h''

However, this equivalent piece is alright:

test2 :: Int
test2 = let g = \s -> s + s
            f = \u -> let h = \t -> t + t; h' = \v -> v + v
                      in  g (h (h' u))
        in f 1 

I believe it is a problem of my syntax, but I can't see anything wrong in test1. Thanks.

EDIT: Thanks for pointing the right way to find the problem. It turns out having to do with the vim-haskellConceal plugin. I copy-paste-save the code in another editor then switch back to vim and notice a different indent in the nested let-in block. Everything's fine after remove that plugin.

EDIT: I should stop blaming this plug-in as I briefly read its code without finding anything inappropriate. Maybe the "conceal" feature in vim7.3 is the root cause. But I'd rather like to go to my warm and cozy bed...

Это было полезно?

Решение

It does work. I just ran that code and got

~ % ghci Hello.hs 
GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Hello.hs, interpreted )
Ok, modules loaded: Main.
*Main> test1 
8
*Main> 

In other words, make sure you don't have any tab characters (\t) in your code!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top