[Haskell-cafe] Haskell + Windows API = wuh?

Juan Carlos Arevalo Baeza jcab.lists at JCABs-Rumblings.com
Fri May 12 03:52:23 EDT 2006

   It has two problems:

1- It is "a very straightforward wrapper". It's not very 
Haskell-friendly. Which might be a good thing or not, I'm not yet sure. 
It could use some more type-safety.
2- It won't allow you to do work on a thread separate from your 
message-loop thread, as any self-respecting Windows program should 
always do. I hope GHC might support that in the future (supporting bound 
threads), but I'm not sure what/if there are any plans about it.

   "ihope", you might want to try the bindings I used when the Win32 
library was broken in 6.4.0:

http://www.JCABs-Rumblings.com/files/Win32Haskell.zip (650K)

   It's not perfect, and it's by no means complete, but I think it's a 
bit better organized and readable than the standard Win32 library you 
get with GHC, and it's much more type-safe, and it's pure Haskell with 
FFI (no C or greencard or anything) so it might give you a better clue 
about how FFI works. It is very simple, actually. Look for all the 
Foreign.hs files, and see how the functions defined there are used 

   You won't find any documentation in there, of course.

   Compile the two silly programs with GHC 6.4.2 like this:

ghc -optl-mwindows -fglasgow-exts -fallow-undecidable-instances 
-fallow-overlapping-instances -lKernel32 -lUser32 -lGdi32 -lOle32 
-lComctl32 -optc-D_WIN32_IE=0x700 -optc-D_WIN32_WINNT=0x600 --make -o 
Win32Test.exe Win32Test.hs

ghc -optl-mwindows -fglasgow-exts -fallow-undecidable-instances 
-fallow-overlapping-instances -lKernel32 -lUser32 -lGdi32 -lOle32 
-lComctl32 -optc-D_WIN32_IE=0x700 -optc-D_WIN32_WINNT=0x600 --make -o 
DictDisp1.exe DictDisp1.hs

   Remove the "-optl-mwindows" if you want the compiler to run on a 
console, so you can see the stdout spew.

   Any comments are very welcome, but make sure you copy me directly or 
I might not catch them :). And let me know if this helps.


Neil Mitchell wrote:
> Hi,
> Pretty much every Haskell implementation supports the FFI - its a
> standardised Haskell 98 extension. Take a look at the System.Win32
> library which is a wrapper round the Windows API. If you have a
> reference to the Win32 API (i.e. MSDN) then the API looks like a very
> straightforward wrapper.
> Thanks
> Neil
> On 5/2/06, ihope <ihope127 at gmail.com> wrote:
>> Ello. I'm looking for a way to interface the Windows API with Haskell
>> in order to write a Win32 console handler thingy. I don't know
>> anything about the Haskell Foreign Function Interface beyond what its
>> name implies and that it's an extension to Haskell 98 (or is it?). So
>> just where do I start?
>> --ihope
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list