Graham Hutton's calculator example for win32
Ahn, Ki Yung
kyagrd at gmail.com
Sun Dec 21 08:34:28 EST 2008
In Graham Hutton's "Programming in Haskell" there is an interactive
calculator example using ANSI code to implement the UI on the terminal.
This example doesn't work on MS Windows XP or other MS OSes based on NT
kernel, since their command line does not support ANSI very well.
But, thanks to ansi-terminal on Hackage, I was able to extract minimal
code from the package to make a win32 version of the calculator example
in Hutton's book.
calculatorWin32.lhs and Win32ANSI.hs is an implementation for win32.
I extracted the win32 console API bindings for setting cursor positions
from ansi-terminal project and put them in Win32ANSI.hs. I had to put
this in a separate file because I had an issue with ghci. To run this,
I had to compile the console API bindings with ghc first and then run
ghci as follows
C:\> ghc -c Win32ANSI.hs
C:\> ghci calculatorWin32.lhs
Without compiling the object code, ghci cannot find the proper link for
win32 console API FFI bindings.
C:\> ghci calculatorWin32.lhs
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 3] Compiling Parsing ( Parsing.lhs, interpreted )
[2 of 3] Compiling Win32ANSI ( Win32ANSI.hs, interpreted )
During interactive linking, GHCi couldn't find the following symbol:
GetConsoleScreenBufferInfo at 8
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session. Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
glasgow-haskell-bugs at haskell.org
Is this a bug or a natural behavior of ghci? This is strange to me
since ghci finds the proper link for the functions in the other C
libraries such as getch in conio.h.
In addition, I am attaching a patched calculator.lhs which works
for Unix/Linux on both GHC 6.8.x and GHC 6.10.1. The one currently
on the book homepage only works for GHC 6.8.x but not GHC 6.10.1.
This is due to the bug fix of hSetBuffering in GHC 6.10.1.
To run these calculator example you will also need Parsing.lhs from
the book hompage. http://www.cs.nott.ac.uk/~gmh/Parsing.lhs
--
Ahn, Ki Yung
-------------- next part --------------
A non-text attachment was scrubbed...
Name: calculatorWin32.lhs
Type: text/x-literate-haskell
Size: 6328 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20081221/c570be8f/calculatorWin32.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Win32ANSI.hs
Type: text/x-haskell
Size: 8105 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20081221/c570be8f/Win32ANSI.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: calculator.lhs
Type: text/x-literate-haskell
Size: 5984 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20081221/c570be8f/calculator.bin
More information about the Glasgow-haskell-users
mailing list