views:

266

answers:

4

I want to learn Ocaml or Haskell and I want to do it by writing a simple game. Apparently, there's one small problem: nobody cares about Windows and I want to do it on Windows, natively.

Haskell has Cabal, which has SDL, but it doesn't build due to a trivial problem with no workarounds (order of parameters passed to gcc). Ocaml doesn't even have that, it's all in source packages, be it GLCaml or OcamlSDL or whatever.

Is there a place where I can get a working SDL for Haskell or Ocaml on Windows without fighting with a dozen versions of compilers?

+6  A: 

The Haskell Platform comes with a binding to OpenGL which should work out of the box on Windows.

Concerning the SDL package on hackage, you can use cabal unpack SDL to get the source code and fix things yourself. To install the package with your changes, run cabal install in the unpacked directory. In any case, drop a line to the maintainer, I'm sure he'll help out.

Heinrich Apfelmus
the problem AFAIK isn't even in the package; [here's a more detailed explanation](http://jpmoresmau.blogspot.com/2010/05/haskell-sdl-on-windows-check-hacking.html).
Baczek
Ah, yuck! The problem that the SDL library redefines your `main` function with a CPP macro. The actual `main` function is in the DLL! This is probably why the linker arguments have to be interchanged. In short, the blame lies with libSDL, whose design doesn't play well with any kind of foreign interface.
Heinrich Apfelmus
I guess your only recourse is to temporarily install a custom version of hsc2hs with JP Moresau's fix. Or you can be really sneaky and replace GCC with a wrapper program that interchanges the arguments before passing them to the real GCC.
Heinrich Apfelmus
And even once you have hsSDL installed, the fun continues, because SDL expects to work its CPP macro magic on applications using it, which works not so well if the entry point is Haskell's `main`. The easiest solution there seems to be exporting your real `main` through the FFI, and calling it from a small C wrapper that SDL can mangle as it pleases.
camccann
+1  A: 

It's not related to SDL, but you've mentioned OpenGL. There is LablGL binding for OpenGL in OCaml which works out of the box. Wiki example (http://en.wikipedia.org/wiki/Objective_Caml#Triangle_.28graphics.29) compiles and works just fine.

balazar
It seems that it only supports the ancient variant of OpenGL - I don't see vertex/fragment programs, etc.
Baczek
+1  A: 

The best instructions I've found for getting SDL to work in windows with a the most recent Haskell platform can be found at this blog. I followed everything step-by-step and it worked perfectly, despite some configure error messages.

Dave B
A: 

It isn't SDL but GLFW works on Windows with Haskell through Cabal.

stonemetal