Re: [Haskell-cafe] function composition

2012-01-15 Thread Daniel Fischer
On Sunday 15 January 2012, 16:17:24, TP wrote: > Hi, > > I have a basic question concerning function composition. I have used > http://www.haskell.org/tutorial/functions.html > to write a composition function: > > Prelude> let f°g = f g This does not what you probably expect. That definition mea

Re: [Haskell-cafe] function composition

2012-01-15 Thread Mike Burns
What you've actually defined is function application. Function composition has a different type: (.) :: (b -> c) -> (a -> b) -> a -> c (I'd read this as: compose takes a function from b to c, a function from a to b, and something of type a, and produces a c.) You ran into an order of operatio

[Haskell-cafe] function composition

2012-01-15 Thread TP
Hi, I have a basic question concerning function composition. I have used http://www.haskell.org/tutorial/functions.html to write a composition function: Prelude> let f°g = f g Prelude> let p = (*2) Prelude> let q = (+3) Prelude> p°q 4 14 Prelude> :t (°) (°) :: (t1 -> t) -> t1 -> t If I understa

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

2011-08-24 Thread Ertugrul Soeylemez
dokondr 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-ev

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

2011-08-24 Thread Jonas Almström Duregård
Hi, > if param1 >    then sp = f1 . f2 . f3 >    else sp = f1 . f3 If you have many situations like these, i.e. where one or several components are conditional, you can define a function when True f = f when False _ = id And now you can define sp like this: sp = f1 . when param1 f2 . f3 Rega

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 > fun

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 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

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

2011-08-24 Thread dokondr
On Wed, Aug 24, 2011 at 4:44 PM, Iustin Pop 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 recompi

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 runAUserSpecifiedComposi

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 f

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

2011-08-24 Thread dokondr
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,

Re: [Haskell-cafe] Function composition questions from a newbie

2009-12-01 Thread Daniel Fischer
Am Dienstag 01 Dezember 2009 10:32:24 schrieb newbie2009: > leledumbo wrote: > > None of them are legal, at least in my WinHugs they're not. What tools > > are you using? > > 1) I am using GHCi. I put the following into a file named composition.hs > and typed ":l composition.hs" in GHCi. I also did

Re: [Haskell-cafe] Function composition questions from a newbie

2009-12-01 Thread newbie2009
leledumbo wrote: > > None of them are legal, at least in my WinHugs they're not. What tools are > you using? > 1) I am using GHCi. I put the following into a file named composition.hs and typed ":l composition.hs" in GHCi. I also did a ":browse Main" 2) Next, I installed WinHugs, and loaded th

Re: [Haskell-cafe] Function composition questions from a newbie

2009-12-01 Thread leledumbo
> I dont understand why the above functions are legal, and what arguments they need. Could you please > give an example of how to invoke it? Huh? None of them are legal, at least in my WinHugs they're not. What tools are you using? Some good reading I found: http://learnyouahaskell.com/higher-or

Re: [Haskell-cafe] Function composition questions from a newbie

2009-12-01 Thread newbie2009
I am a newbie. Consider this code: square x = x * x add3 x y z = x + y + z leledumbo wrote: > > > what about (square . add3) 1 2? > > It doesn't work since add3, when curried (arguments of square "blended" > with add3's) with 1 argument becomes: > > add3 :: Num a => a -> a -> a > > whic

Re: [Haskell-cafe] Function composition questions from a newbie

2009-11-30 Thread leledumbo
> This doesnt. But why? Back to the definition of function composition: f . g is possible if g returns a value that's compatible with f's argument. Now, let's check the type of square and add3: square :: Num a => a -> a add3 :: Num a => a -> a -> a -> a (square . add3 1 2) is actually seen by t

Re: [Haskell-cafe] Function composition questions from a newbie

2009-11-30 Thread muad
newbie2009 wrote: > > I am a newbie. Consider this code: > > square x = x * x > add3 x y z = x + y + z > add x y = x + y > composition5 x = (square . add3) x > composition6 x y = (square . add3) x y > > 1) What arguments can i pass to composition5? Please give an example of > calling it. > 2

Re: [Haskell-cafe] Function composition

2008-12-30 Thread Henning Thielemann
On Mon, 29 Dec 2008, Martijn van Steenbergen wrote: Conal Elliott wrote: If you think of f (here f=not) as an "semantic editor" (transformer) of values, then 'result', 'first', and 'second' are "semantic editor combinators", which can be composed together arbitrarily. See http://conal.net/b

Re: [Haskell-cafe] Function composition

2008-12-29 Thread Conal Elliott
I hadn't seen data-accessor before. Thanks for the pointer. - Conal On Mon, Dec 29, 2008 at 1:34 PM, Martijn van Steenbergen < mart...@van.steenbergen.nl> wrote: > Conal Elliott wrote: > >> If you think of f (here f=not) as an "semantic editor" (transformer) of >> values, then 'result', 'first'

Re: [Haskell-cafe] Function composition

2008-12-29 Thread Martijn van Steenbergen
Conal Elliott wrote: If you think of f (here f=not) as an "semantic editor" (transformer) of values, then 'result', 'first', and 'second' are "semantic editor combinators", which can be composed together arbitrarily. See http://conal.net/blog/semantic-editor-combinators . I recently found ou

Re: [Haskell-cafe] Function composition

2008-12-29 Thread Conal Elliott
Hi Oscar, Define result = (.) Then '(result f) g' applies f to the result part of a function g. That's what you want when negating the result of not. For (==), you want to negate the result of the result, so you'd instead say '(result.result) not (==)'. Keep composing result for deeper app

Re: [Haskell-cafe] Function composition

2008-12-29 Thread Henning Thielemann
Luke Palmer schrieb: > 2008/12/26 Oscar Picasso > > > Hi, > > I can write: > *Main> let yes = not . not > *Main> :t yes > yes :: Bool -> Bool > > But not: > *Main> let isNotEqual = not . (==) > > > The definition of (.): > > f . g =

Re: [Haskell-cafe] Function composition

2008-12-27 Thread Roman Cheplyaka
* Roman Cheplyaka [2008-12-27 11:33:22+0200] > * Oscar Picasso [2008-12-26 22:37:26-0500] > > Hi, > > > > I can write: > > *Main> let yes = not . not > > *Main> :t yes > > yes :: Bool -> Bool > > > > But not: > > *Main> let isNotEqual = not . (==) > > > > :1:23: > > Couldn't match expected

Re: [Haskell-cafe] Function composition

2008-12-27 Thread Roman Cheplyaka
* Oscar Picasso [2008-12-26 22:37:26-0500] > Hi, > > I can write: > *Main> let yes = not . not > *Main> :t yes > yes :: Bool -> Bool > > But not: > *Main> let isNotEqual = not . (==) > > :1:23: > Couldn't match expected type `Bool' >against inferred type `a -> Bool' > Probab

Re: [Haskell-cafe] Function composition

2008-12-26 Thread Tony Morris
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Check the type of (.) Prelude> :t (.) (.) :: (b -> c) -> (a -> b) -> a -> c Then the type of (.) not Prelude> :t (.) not (.) not :: (a -> Bool) -> a -> Bool Now try to apply (==) Prelude> :t (.) not (==) -- not going to happen Won't happen. What

Re: [Haskell-cafe] Function composition

2008-12-26 Thread Luke Palmer
2008/12/26 Oscar Picasso > Hi, > > I can write: > *Main> let yes = not . not > *Main> :t yes > yes :: Bool -> Bool > > But not: > *Main> let isNotEqual = not . (==) The definition of (.): f . g = \x -> f (g x) So: not . (==) = \x -> not ((==) x) But (==) x is a function (of type a -> Bool,

[Haskell-cafe] Function composition

2008-12-26 Thread Oscar Picasso
Hi, I can write: *Main> let yes = not . not *Main> :t yes yes :: Bool -> Bool But not: *Main> let isNotEqual = not . (==) :1:23: Couldn't match expected type `Bool' against inferred type `a -> Bool' Probable cause: `==' is applied to too few arguments In the second argumen

Re: [Haskell-cafe] Function composition

2007-10-03 Thread Jorge Marques Pelizzoni
Here is a generalized version, using type classes and some extensions. Tiago, in order to compile this you'll have to use: -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances Cheers, Jorge. - module Main where class Pipeline t1 t2 t3 | t1 t2 -> t3 where

Re: [Haskell-cafe] Function composition

2007-10-03 Thread Ryan Ingram
On 10/3/07, Tiago Miguel Laureano Alves <[EMAIL PROTECTED]> wrote: > Imagine that I have the following functions >f :: a -> b -> c -> d >g :: d -> e > > I want to compose these two functions such that: >(g . f) :: a -> b -> c -> e Here's a pointfree derivation of the composition functi

[Haskell-cafe] Function composition

2007-10-03 Thread Tiago Miguel Laureano Alves
Hi, I'm playing a little bit with pointfree and function composition and I would like to ask you if the following is theoretical correct and how can I express it in haskell. Imagine that I have the following functions f :: a -> b -> c -> d g :: d -> e I want to compose these two func

Re: [Haskell-cafe] Function Composition

2007-02-06 Thread Andres Loeh
> Can anyone explain why Shape.Polygon would have a different type to > (Shape).Polygon, I thought the brackets would be redundant. Here is > the output from a Hugs session > > Animation> :v > -- Hugs Version 20050113 > Animation> :t Shape > Shape :: Shape -> Region > Animation> :t Polygon > Polyg

[Haskell-cafe] Function Composition

2007-02-06 Thread Chris Witte
Can anyone explain why Shape.Polygon would have a different type to (Shape).Polygon, I thought the brackets would be redundant. Here is the output from a Hugs session Animation> :v -- Hugs Version 20050113 Animation> :t Shape Shape :: Shape -> Region Animation> :t Polygon Polygon :: [Vertex] -> S

Re: [Haskell-cafe] Function composition confusion

2005-04-27 Thread Benjamin Franksen
On Wednesday 27 April 2005 15:46, Anuj Seth wrote: > Thanks, that clears it up > I was thinking that the output of (splitAt blockSize) would get piped to > (splitAt blockSize . snd). Did not realize it goes to the whole iterate > part. It is useful to keep in mind that function application ('f x')

RE: [Haskell-cafe] Function composition confusion

2005-04-27 Thread Anuj Seth
To: Anuj Seth Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Function composition confusion On Wed, 27 Apr 2005, Anuj Seth wrote: > Excuse the newbie'ness of my question. > Saw an example in Two Dozen Questions by Rexx Page. > > blocks blockSize = >takeWhile

Re: [Haskell-cafe] Function composition confusion

2005-04-27 Thread Henning Thielemann
On Wed, 27 Apr 2005, Anuj Seth wrote: Excuse the newbie'ness of my question. Saw an example in Two Dozen Questions by Rexx Page. blocks blockSize = takeWhile ( not . null ) . map fst . iterate (splitAt blockSize . snd) . splitAt blockSize What is the meaning of the . operators outsi

[Haskell-cafe] Function composition confusion

2005-04-27 Thread Anuj Seth
Hi, Excuse the newbie'ness of my question. Saw an example in Two Dozen Questions by Rexx Page. blocks blockSize = takeWhile ( not . null ) . map fst . iterate (splitAt blockSize . snd) . splitAt blockSize What is the meaning of the . operators outside the parentheses ? Thsi doe