[Haskell-beginners] dealing with chained functions

Alec Benzer alecbenzer at gmail.com
Sat Sep 4 00:52:15 EDT 2010


Is there a generally accepted "better" way of dealing with the following:

say I have three functions that all rely on output from each other. Ie, we
get raw input, which one function processes. another function then requires
the output from this function and produces some other output, which a third
function then requires. would it be better to implement the functions like
this:

f1 :: a -> b
f2 :: b -> c
f3 :: c -> d
final :: a -> d

or like this:

f1 :: a -> b
f2 :: a -> c
f3 :: a -> d

Ie, in the latter set, f2 calls f1 on its input, and then proceeds to
process it. f3 calls f2 on its input, etc. In the former case, final would
just chain all three functions together itself (or I might just do it in
main or somewhere else that's appropriate)

Are one of these methods generally considered a better practice than the
other, specifically in a functional context? My gut tells me that the former
method looks more appropriate, but I'm not sure if it'd really be the
accepted practice regardless of context, or if one might use either of these
methods depending on the specifics of what they're doing. Or if it's just a
matter of taste/opinion?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100903/e00a6553/attachment-0001.html


More information about the Beginners mailing list