[Haskell-cafe] Re: different code in different platforms

2006-03-17 Thread Ben Rudiak-Gould

Neil Mitchell wrote:

#ifdef __WIN32__
(Windows code)
#else
(Linux code)
#endif


In Yhc, we use a runtime test to check between Windows and Linux.


I think the cleanest solution is to factor the OS-specific code into 
separate modules with OS-independent interfaces and names, and pull in the 
appropriate implementations at compile time by changing the module search 
path. That way you avoid the syntactic and semantic ugliness of cpp as well 
as most of the practical problems of a runtime test.


You can also use any two or all three of these techniques together.

-- Ben

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: different code in different platforms

2006-03-15 Thread John Meacham
On Wed, Mar 15, 2006 at 04:13:19PM +, Simon Marlow wrote:
> There's a lot to be said for using runtime tests instead of conditional 
> compilation, I agree.  However, it can't be used exclusively: you can't 
> choose between two foreign calls this way, for example, because one of 
> the calls won't link.

A scheme I was considering for jhc was to (optionally) replace any foreign 
calls that
don't link with 'error', a solution for ghc might be to include stub
functions with the 'weak' attribute set in the object file for any
potentially non-existing functions. then the system versions will
override them if they exist, otherwise the stub functions will be
called.

perhaps there is room for a FFI extension there? allowing 'weak' to be
specified on FFI imports that means 'don't complain if the system
doesn't provide this function'

John

-- 
John Meacham - ⑆repetae.net⑆john⑈
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: different code in different platforms

2006-03-15 Thread Simon Marlow

Neil Mitchell wrote:


Does it really have to change statically?



I use code like:
#ifdef __WIN32__
   (Windows code)
#else
   (Linux code)
#endif



In Yhc, we use a runtime test to check between Windows and Linux. It
has various advantages - we only have one code base, everything is
type checked when we compile, and we've never run into any problems
once despite developing on two different platforms.

http://www-users.cs.york.ac.uk/~malcolm/cgi-bin/darcsweb.cgi?r=yhc-devel;a=headblob;f=/src/compiler98/Util/FilePath.hs


There's a lot to be said for using runtime tests instead of conditional 
compilation, I agree.  However, it can't be used exclusively: you can't 
choose between two foreign calls this way, for example, because one of 
the calls won't link.


Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe