Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread Iustin Pop
On Wed, Aug 24, 2011 at 04:35:42PM +0400, dokondr wrote:
 Hi,
 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.

A simple alternative to if would be:

  options = [ (foo, f1 . f2 . f3)
, (bar, f1 . f3 )]

and then lookup param options. I don't know if this is what you're
looking for, though.

regards,
iustin

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


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread Arseniy Alekseyev
If your functions have the same type, then you can easily collect them
in a data structure, say list, and fold that.

For example:

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 doko...@gmail.com wrote:
 Hi,
 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.

 Thanks,
 Dmitri






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



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


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread dokondr
On Wed, Aug 24, 2011 at 4:44 PM, Iustin Pop ius...@google.com wrote:

 On Wed, Aug 24, 2011 at 04:35:42PM +0400, dokondr wrote:
  Hi,
  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.


A simple alternative to if would be:

  options = [ (foo, f1 . f2 . f3)
, (bar, f1 . f3 )]

 and then lookup param options. I don't know if this is what you're
 looking for, though.


Thanks!
Yes, this is what I need - simple and easy. Yet, how function application
will work in this case ?
I mean after lookup returns me a composition ... need to check what type
will it be.

-- 
All the best,
dokondr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread Iustin Pop
On Wed, Aug 24, 2011 at 04:57:19PM +0400, dokondr wrote:
 On Wed, Aug 24, 2011 at 4:44 PM, Iustin Pop ius...@google.com wrote:
 
  On Wed, Aug 24, 2011 at 04:35:42PM +0400, dokondr wrote:
   Hi,
   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.
 
 
 A simple alternative to if would be:
 
   options = [ (foo, f1 . f2 . f3)
 , (bar, f1 . f3 )]
 
  and then lookup param options. I don't know if this is what you're
  looking for, though.
 
 
 Thanks!
 Yes, this is what I need - simple and easy. Yet, how function application
 will work in this case ?
 I mean after lookup returns me a composition ... need to check what type
 will it be.

Well, as with your 'if', all compositions must have the same type, since
lists are homogeneous.

regards,
iustin

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


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread dokondr
On Wed, Aug 24, 2011 at 4:52 PM, Arseniy Alekseyev 
arseniy.alekse...@gmail.com wrote:

 If your functions have the same type, then you can easily collect them
 in a data structure, say list, and fold that.

 For example:

 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.


This is a nice one, looks already like tiny DSL )

I think I've got the main idea - enumerate in my program all function
compositions in some data structure for Haskell to compile, and the
associate these with parameter values in external file.

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


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread Ertugrul Soeylemez
dokondr doko...@gmail.com wrote:

 This is a nice one, looks already like tiny DSL )

 I think I've got the main idea - enumerate in my program all function
 compositions in some data structure for Haskell to compile, and the
 associate these with parameter values in external file.

In Haskell you get a not-even-too-tiny DSL for free for composing
functions in arbitrary, dynamic ways.  Hint:  (a -) is a monad and (-)
is an ArrowChoice and an ArrowApply.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://ertes.de/



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