haskell-cafe@haskell.org
[Top] [All Lists]

Re: [Haskell-cafe] separate input calculation output

Subject: Re: [Haskell-cafe] separate input calculation output
From: Ketil Malde
Date: Tue, 25 Mar 2008 11:10:36 +0100
Thomas Engel <thomas.engel1@xxxxxxx> writes:

> My problem is: How can I get the input values into the calculations and back
> the result to the output.

> In an other language I would use global variables for this. 

That would be bad style.

> An other point is that I want to separate the input from the calculations and
> the output.

> So what should I use in haskell?

I think your pseudocode is right on track.

> inputvalues  ::  IO ()

The most obvious way to do it would be to define

    data Input = ...
    data Output = ...

    input_values :: IO Input
    
    calculate :: Input -> Output
    
    ouput_values :: Output -> IO ()

then:

    main = do i <- input_values
              let o = calculate i
              output_values o

or:  
    main = output_values . calculate =<< input_values

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>