Anton Rolls wrote:

>I am not completely sure what function composition means.
>Pixel said: "function composition is a function taking 2
>functions and returning a new one."
>
>Looking at some Haskell posts I see it kind of
>glues two functions together, passing the result
>from the first function into the second one.
>There are (resolvable) problems when the number of
>arguments are not the same, but, anyway...
>Doesn't this just mean that this is function
>composition:
>
>       add: func [a b][a + b]
>       mul3: func [a][a * 3]
>       add-mul3: func [a b][mul3 add a b]
>
>?
>Or it doesn't count because the "composition"
>is specified in the body block, whereas Haskell
>does it by referring only to the function names.
>  
>
It "doesn't count", an answer in Rebol (needs some polishing):

    composition: func [
        f [any-function!]
        g [any-function!]
    ] [
        use [f' g' body] copy/deep [
            f': :f
            g': :g
            body: [f' g']
            foreach arg first :g [
                insert tail body reduce ['get/any to lit-word! arg]
            ]
            func load mold third :g body
        ]
    ]

Usage:

    add-mul3: composition :mul3 :add

-Ladislav

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to