[Haskell-cafe] Fucntion composing

Ozgur Akgun ozgurakgun at gmail.com
Tue Apr 12 02:18:58 CEST 2011


In addition to what others have said, you could use pointfree[1] to do this
automagically!

>> pointfree "h x y = (g 0 (f x y))"
h = (g 0 .) . f

[1] http://hackage.haskell.org/package/pointfree

On 11 April 2011 10:22, Adam Krauze <ajschylos at mac.com> wrote:

> Hello,
> as I am newbie to Haskell  and my introductory question is:
>
> given functions say f and g with type signatures
>
> f :: (Num a) => [a] -> [a] -> [(a,a)]  // f takes two lists and zips them
> into one in some special way
> g :: (Num a) => a -> [(a,a)] -> [a]  // g using some Num value calculates
> list of singletons from list of pairs
>
> of course  g 0 :: (Num a) => [(a,a)] ->[a]
>
> now I want to create function h :: (Num a) => [a] -> [a] -> [a] in such way
>
> that (g 0) consumes output of f.
>
> But when I try
>
> Prelude> :t (g 0).f
>
> I get an error:
>
> <interactive>:1:9:
> Couldn't match expected type `[(a0, a0)]'
>                with actual type `[a1] -> [(a1, a1)]'
>    Expected type: [a1] -> [(a0, a0)]
>      Actual type: [a1] -> [a1] -> [(a1, a1)]
>    In the second argument of `(.)', namely `f'
>    In the expression: (g 0) . f
>
> In pointfull representation it works well
>
> Prelude> let h x y = (g 0 (f x y))
>
> How to do pointfree definition of h?
>
> Ajschylos.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110412/08d85ad9/attachment-0001.htm>


More information about the Haskell-Cafe mailing list