Dulguun Otgon
Dulguun Otgon

Reputation: 1949

Programming in Haskell book's some code not working

I'm on the chapter 9.6 of book Programming in Haskell, page 91. The function writeat is supposed to write given string on given location on the command prompt but this is not working for me.

type Pos = (Int, Int)

goto        :: Pos -> IO ()
goto (x, y) = putStr ("\ESC[" ++ show y ++ ";" ++ show x ++ "H")

writeat     :: Pos -> String -> IO ()
writeat p xs = do
    goto p
    putStr xs

But it is not doing what the book says. Is it because I'm on Windows? If so is there a workaround?

Upvotes: 4

Views: 204

Answers (1)

bazzargh
bazzargh

Reputation: 1852

Yes, it's because you are on windows. Those are ANSI escape sequences, and Windows doesn't support them: http://en.wikipedia.org/wiki/ANSI_escape_code#Windows_and_DOS

You can possibly work around this by using cygwin with mintty, and making sure your TERM is set to one that support ANSI; or run your haskell in a linux VM, using an xterm (like this VM from fpcomplete: https://www.fpcomplete.com/page/haskell-eval-vm) . But it's not worth all that effort for this example.

Upvotes: 4

Related Questions