Re: [Haskell-cafe] Ignorant begginer question

2004-12-23 Thread Jon Fairbairn
On 2004-12-23 at 15:09-0200 =?ISO-8859-1?Q?Maur=EDcio?= wrote:
Guys,
 
What is wrong with this code?
 
 **
 import Complex
 roots :: (Complex, Complex, Complex) - (Complex, Complex);
 roots (a,b,c) = (x1,x2) where { x1 = (b*b + (sqrt_delta))/(2*a); x2 = 
 (b*b - (sqrt_delta))/(2*a); sqrt_delta = sqrt 4*a*c}
 **
 
I load it into GHCi and get:
 
 **
 Kind error: `Complex' is not applied to enough type arguments

That means what it says: Complex takes an argument, namely
the type for the real and imaginary parts.  You need to
choose from Float, Double or some RealFloat.

Try this in ghci:

   Prelude :m Complex
   Prelude Complex :info Complex
   -- Complex is a type constructor
   data (RealFloat a) = Complex a = (:+) !a !a

and then

 type Compl = Complex Double
 roots :: (Compl, Compl, Compl) - (Compl, Compl)

-- 
Jón Fairbairn [EMAIL PROTECTED]


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ignorant begginer question

2004-12-23 Thread Jules Bean
On 23 Dec 2004, at 17:09, Maurício wrote:
Kind error: `Complex' is not applied to enough type arguments
Complex is a type constructor.
Complex Double (e.g.) is a type.
So try
roots :: (Complex Double, Complex Double, Complex Double) - (Complex 
Double, Complex Double);

or indeed
roots :: (RealFloat t) = (Complex t, Complex t, Complex t) - (Complex 
t, Complex t);

Jules
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ignorant begginer question

2004-12-23 Thread Stefan Holdermans
Maurício,
What is wrong with this code?
I'm sorry, I don't have time to tell the whole story on kinds right 
now, so you'll have to do it with this practical solution. Maybe 
someone else will jump in and give you the grand tour on kinds.

Your problem right now is that the type Complex takes (needs) a type 
argument. Its definitions is (module strictness flags):

  data Complex a = a :+ a
So, what you have to do, is applying Complex to a type argument.
For instance,
  roots :: (Complex Double, Complex Double, Complex Double)
 - (Complex Double, Complex Double)
or
  roots :: (Complex Float, Complex Float, Complex Float)
 - (Complex Float, Complex Float)
or, more general, and therefore probably better,
  roots :: (RealFloat a) = (Complex a, Complex a, Complex a)
 - (Complex a, Complex a);
HTH,
Stefan
On Dec 23, 2004, at 6:09 PM, Maurício wrote:
  Guys,
  What is wrong with this code?
**
import Complex
roots :: (Complex, Complex, Complex) - (Complex, Complex);
roots (a,b,c) = (x1,x2) where { x1 = (b*b + (sqrt_delta))/(2*a); x2 = 
(b*b - (sqrt_delta))/(2*a); sqrt_delta = sqrt 4*a*c}
**

  I load it into GHCi and get:
**
Kind error: `Complex' is not applied to enough type arguments
In the type: (Complex, Complex, Complex) - (Complex, Complex)
While checking the type signature for `roots'
Failed, modules loaded: none.
**
  Thanks,
  Maurício

___
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