
No, still no idea! I tried curry f where f :: (Num a) => (a, a) -> a and it didn't like it. For some reason I'm finding this a little chalenging. Thanks, Paul At 17:03 03/10/2007, you wrote:
On 10/3/07, PR Stanley <mailto:prstanley@ntlworld.comprstanley@ntlworld.com> wrote: I didn't even know about the curry and uncurry functions. I'm not looking for the answer but some guidance would be much appreciated. Thanks, Paul
You can look at the types without seeing the implementation, too. Just start up GHCI and type:
:t curry
or
:t uncurry
Justin

Here is one trick I have found useful on occasion: Prelude> :t let f = undefined :: (Num a) => (a,a) -> a in curry f let f = undefined :: (Num a) => (a,a) -> a in curry f :: (Num a) => a -> a -> a undefined (also called bottom) is an element of every type, so if you just need "something" with a given type, you can write undefined :: YOUR_TYPE_HERE If you're having typing troubles in a complex expression, stick in annotated (i.e. the suffix :: SOME_TYPE) unknowns as placeholders, then replace them until the type breaks. Use parentheses (undefined :: TYPE) to be sure, since the binding strength of :: is not high. PR Stanley wrote:
No, still no idea! I tried curry f where f :: (Num a) => (a, a) -> a and it didn't like it. For some reason I'm finding this a little chalenging. Thanks, Paul At 17:03 03/10/2007, you wrote:
On 10/3/07, PR Stanley <mailto:prstanley@ntlworld.comprstanley@ntlworld.com> wrote: I didn't even know about the curry and uncurry functions. I'm not looking for the answer but some guidance would be much appreciated. Thanks, Paul
You can look at the types without seeing the implementation, too. Just start up GHCI and type:
:t curry
or
:t uncurry
Justin
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Warning: I hope I haven't spoiled the answer to this problem. If so, read only until the answer becomes clear! I think the key is to be quite clear about what it is the function should do. Reading the type helps: Prelude> :t curry curry :: ((a, b) -> c) -> a -> b -> c This type signature looks a bit confusing, but in fact, we can separate it into two chunks: curry :: ((a, b) -> c) -> (a -> b -> c) The first chunk is the input, and the second chunk is the output, obviously. So what this means is that curry takes a function which sends (a, b) pairs to a new type c, and returns a function which takes two arguments (*), a variable of type a, and one of type b, and returns a c. So our implementation will have to take a function as its argument: curry f = [implementation] Also, we know that curry should itself return a function. Although we don't yet know the definition of that function, let's declare it and return it anyway: curry f = let <definition of curriedFn> in curriedFn But what should curriedFn do? Well we know that it should replicate the behaviour of f. But we also know that it's arguments need to be translated, so that the two arguments (one of type a, and one of type b) become a *single* argument of type (a, b). Can you think of a definition of curriedFn so that when it is called with the arguments x, y, it in turn produces the same result as calling f (x, y) ? HTH Martin (*) yes, I am aware that the internally all functions take just one parameter. PR Stanley wrote:
No, still no idea! I tried curry f where f :: (Num a) => (a, a) -> a and it didn't like it. For some reason I'm finding this a little chalenging. Thanks, Paul At 17:03 03/10/2007, you wrote:
On 10/3/07, PR Stanley <mailto:prstanley@ntlworld.comprstanley@ntlworld.com> wrote: I didn't even know about the curry and uncurry functions. I'm not looking for the answer but some guidance would be much appreciated. Thanks, Paul
You can look at the types without seeing the implementation, too. Just start up GHCI and type:
:t curry
or
:t uncurry
Justin
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Dan Weston
-
Martin Percossi
-
PR Stanley