
Roelof Wobben
Hello,
I have to find the center of 2 points as a assigment for a course on fpcomplete. This is no homework because I do a self-study.
So I did this:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center ((1,2), (3, 4))
should be: center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center (1,2) (3, 4)
but now I see this error message :
Main.hs@2:8-2:13
* No instance for (Show (((t0, t1), (t2, t3)) -> ((t0, t1), (t2, t3)))) arising from a use of `print' Possible fix: add an instance declaration for (Show (((t0, t1), (t2, t3)) -> ((t0, t1), (t2, t3)))) In the expression: print In the expression: print $ center ((1, 2), (3, 4)) In an equation for `main': main = print $ center ((1, 2), (3, 4))
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Mathijs Kwik schreef op 10-5-2014 13:55:
Roelof Wobben
writes: Hello,
I have to find the center of 2 points as a assigment for a course on fpcomplete. This is no homework because I do a self-study.
So I did this:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center ((1,2), (3, 4)) should be:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center (1,2) (3, 4)
oke, as I see you changed the main function but I have to make the center function work not change the main function. Roelof

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 10/05/14 14:00, Roelof Wobben wrote:
as I see you changed the main function but I have to make the center function work not change the main function. Your center function takes two tuples, but you give it a tuple of two tuples.
(foo, bar) (fu, baz) is not the same as ((foo, bar), (fu, baz)) Do you see this? The latter is one value, a tuple of tuples. The former, which is what your function expects, is two values. Given the function add x y = x+y You are calling it by "add (1, 2)", when you should be calling it simply by "add 1 2". Hope this helped. - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNuFa0ACgkQRtClrXBQc7WaKgEAqqTU61+Kw/SBbqXMXtW9cY+F Og1VJefDYsBKPxzYf/UA/jmJYe075tinDK7fDGvNSvFu8no/NDx8Sl567lWJ/NFm =r8Ol -----END PGP SIGNATURE-----

Hi,
remember that in Haskell argument application is just a space, not using
parenthesis and comma like in some imperative languages.
In Java: myFunc (a, b)
Is equivalent in Haskell to: myfunc a b
so center ((1,2), (3, 4)) is a function applied to only one arguement (a
tuple of tuples)
On Sat, May 10, 2014 at 2:00 PM, Roelof Wobben
Mathijs Kwik schreef op 10-5-2014 13:55:
Roelof Wobben
writes: Hello,
I have to find the center of 2 points as a assigment for a course on fpcomplete. This is no homework because I do a self-study.
So I did this:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center ((1,2), (3, 4))
should be:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center (1,2) (3, 4)
oke,
as I see you changed the main function but I have to make the center function work not change the main function.
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Also, in Haskell all functions take only one parameter. If you want a
function of two (as in the case of center) there are two ways to achieve
that:
Make the argument a tuple or make a function with the first argument
returning another function taking the second. The latter approach is more
common in Haskell.
Your definition of center does that.
foo x y = x *y
is the same as
foo x= \y -> x*y
and
foo = \x -> \y -> x*y
On May 10, 2014 2:05 PM, "Corentin Dupont"
Hi, remember that in Haskell argument application is just a space, not using parenthesis and comma like in some imperative languages. In Java: myFunc (a, b) Is equivalent in Haskell to: myfunc a b so center ((1,2), (3, 4)) is a function applied to only one arguement (a tuple of tuples)
On Sat, May 10, 2014 at 2:00 PM, Roelof Wobben
wrote: Mathijs Kwik schreef op 10-5-2014 13:55:
Roelof Wobben
writes: Hello,
I have to find the center of 2 points as a assigment for a course on fpcomplete. This is no homework because I do a self-study.
So I did this:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center ((1,2), (3, 4))
should be:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center (1,2) (3, 4)
oke,
as I see you changed the main function but I have to make the center function work not change the main function.
Roelof
_______________________________________________ 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

you should do :
main = print $ center (1,2), (3, 4)
On Sat, May 10, 2014 at 1:51 PM, Roelof Wobben
Hello,
I have to find the center of 2 points as a assigment for a course on fpcomplete. This is no homework because I do a self-study.
So I did this:
center (x1,y1) (x2,y2) = ( ((x1+x2)/2),((y1+y2)/2) ) main = print $ center ((1,2), (3, 4))
but now I see this error message :
Main.hs@2:8-2:13
- No instance for (Show (((t0, t1), (t2, t3)) -> ((t0, t1), (t2, t3)))) arising from a use of `print' Possible fix: add an instance declaration for (Show (((t0, t1), (t2, t3)) -> ((t0, t1), (t2, t3)))) In the expression: print In the expression: print $ center ((1, 2), (3, 4)) In an equation for `main': main = print $ center ((1, 2), (3, 4))
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (6)
-
Alexander Berntsen
-
Corentin Dupont
-
Johan Holmquist
-
Mathijs Kwik
-
Osager Prairie
-
Roelof Wobben