1

Trying to implement SKI combinators in Haskell... Im not sure what ^M represents but i think it has something to do with the notation of vim while editing a haskell file. Also what is the type notation of the function eliminate? Thanks

data Exp = Var String | App Exp Exp | Lam String Exp | S | K |I ^M
transform (Lam x y) = (eliminate x y)


eliminate x S = App K S^M
eliminate x K = App K K^M
eliminate x I = App K I^M
eliminate x (Var y)
                | x==y      = I
                | otherwise = (App K (Var y))

eliminate x (Lam y z) = eliminate x (eliminate y z)^M

eliminate x (App y z) = (App (App S (eliminate x y)) (eliminate x z))^M
luqui
  • 59,485
  • 12
  • 145
  • 204
Jung
  • 139
  • 6
  • 3
    Doesn't `^M` stand for "Control-M", which means usually "Enter" or "New line" in most shells and some editors? – radrow Jan 21 '19 at 14:40
  • 6
    Perhaps your file has some inconsistent newline separators: some lines end with CRLF (windows style) while others end with LF only (mac/unix style). Vim opens the file in unix mode, but notices additional CRs around. I'd remove those ^Ms. – chi Jan 21 '19 at 14:57

2 Answers2

2

You have ^M linebreaks. This answer says you can fix it by doing :e ++ff=dos in vim. But I can't ensure you that, since I use emacs.

What do you mean when you say type notation? If you mean the type signature, it is

eliminate :: String -> Exp -> Exp
steve
  • 281
  • 1
  • 5
  • Mateen Ulhaq's comment there indicates that you need to use "`:e ++ff=dos` followed by `:set ff=unix` [to] convert the endings to a sane format." The OP there indicated that that was correct. – dfeuer Jan 21 '19 at 18:19
1

As already stated in some comments some of the lines contain the DOS end-ofline CRLF, some are Unix end-of-line LF. To fix it to Unix only:

:%s/\r$//

I can't say anything about Haskell.

Ralf
  • 1,773
  • 8
  • 17