Is there a an include statement equivalence in Haskell

Hi I have a few lines of Haskell which I'd like to be pulled into my Haskell program, similar to the #include in C/C++, or Latex. I don't want to just paste the code permanently using editor, or pass it through say M4, nor build my own module. At the moment its a couple of lines I've used in three or four similar programs. As a Haskell beginner, is my thinking still stuck in the imperative coding style era ? -- Andrew

"Andrew" == Andrew Smith
writes:
Andrew> Hi I have a few lines of Haskell which I'd like to be pulled Andrew> into my Haskell program, similar to the #include in C/C++, Andrew> or Latex. Andrew> I don't want to just paste the code permanently using Andrew> editor, or pass it through say M4, nor build my own module. Andrew> At the moment its a couple of lines I've used in three or Andrew> four similar programs. Andrew> As a Haskell beginner, is my thinking still stuck in the Andrew> imperative coding style era ? The equivalent is import. Modules are lightweight. As are functions. -- Colin Adams Preston Lancashire

Hi It's generally bad idea to include source code in this manner. It is error prone, hard to understand and ugly. It's really better to use modules instead. But if you *really* want to rely on such hacks, then yes, it's possible. Simply use cpp's #include. But first you need to enable CPP extension. One way of doing it is writing this line as the first line:
{-# LANGUAGE CPP #-}
With cpp in game you can then write:
#include "common.hs"
Best regards
Krzysztof Skrzętnicki
On Wed, Feb 10, 2010 at 12:17, Andrew Smith
Hi I have a few lines of Haskell which I'd like to be pulled into my Haskell program, similar to the #include in C/C++, or Latex.
I don't want to just paste the code permanently using editor, or pass it through say M4, nor build my own module.
At the moment its a couple of lines I've used in three or four similar programs.
As a Haskell beginner, is my thinking still stuck in the imperative coding style era ?
-- Andrew
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Hello Andrew Do the few lines define Haskell expressions (functions or constants) or are they something like a copyright notice (which you want the same in all files)? If they are functions, avoiding putting them in a module would seem a bit dubious. Most people probably have their own collection of 'missing' functions from the Prelude that they share between their projects, (of course everyone has different variations of 'missing' functions...) Best wishes Stephen
participants (4)
-
Andrew Smith
-
Colin Paul Adams
-
Krzysztof Skrzętnicki
-
Stephen Tetley