[Haskell-cafe] Function composition in run-time?
arseniy.alekseyev at gmail.com
Wed Aug 24 14:52:29 CEST 2011
If your functions have the same type, then you can easily collect them
in a data structure, say list, and fold that.
function :: String -> (String -> String)
function "f1" = f1
function "f2" = f2
function "f3" = f3
runAUserSpecifiedComposition :: String -> F
runAUserSpecifiedComposition = foldl (.) id . map function . words
runAUserSpecifiedComposition "f1 f2 f3" should be equal to (f1 . f2 . f3) now.
On 24 August 2011 13:35, dokondr <dokondr at gmail.com> wrote:
> What is the Haskell way to compose functions in run-time?
> Depending on configuration parameters I need to be able to compose function
> in several ways without recompilation.
> When program starts it reads configuration parameters from a text file. For
> example, I have three functions, f1, f2, f3, each doing some string
> processing. I need to support two configurations of string processors :
> if param1
> then sp = f1 . f2 . f3
> else sp = f1 . f3
> I'd like to avoid 'if' somehow and instead use some declarative way to
> specify code to run in external configuration file. In other words I need
> some easy tools to create mini DSLs without all the efforts usually involved
> with implementing full-blown DSL.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe