
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

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 Jon.Fairbairn@cl.cam.ac.uk

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

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

On 24 Dec 2004, at 14:53, John Goerzen wrote:
On 2004-12-23, Stefan Holdermans
wrote: 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
What does the :+ mean here?
It's a data constructor, written infix. Infix constructors all begin with ':', I think. Jules

On Fri, Dec 24, 2004 at 03:14:34PM +0000, Jules Bean wrote:
It's a data constructor, written infix. Infix constructors all begin with ':', I think.
Yes, but you can also use prefix, alphanumeric constructors as infix by placing them in backticks. This can be nice sometimes: data Expr = ... | Expr `In` [Expr] | Expr `And` Expr | Expr `Or` Expr ... case e of e1 `In` es -> ... Best regards, Tomasz
participants (6)
-
John Goerzen
-
Jon Fairbairn
-
Jules Bean
-
Maurício
-
Stefan Holdermans
-
Tomasz Zielonka