Nicholls, Mark | 21 Dec 18:08

RE: nice simple problem for someone struggling....

Oh….

 

You are correct…

 

I thought from

 

“Num numberType => SquareConstructor
numberType”

 

We could deduce that (in English rather than get Haskell and FOL confusion)

 

all values of “SquareConstructor a”….the type of a would have be be in class Num?..

is this not correct?....if not….why not?

 

From: d4ve.menendez <at> gmail.com [mailto:d4ve.menendez <at> gmail.com] On Behalf Of David Menendez
Sent: 21 December 2007 17:05
To: Nicholls, Mark
Cc: Jules Bean; haskell-cafe <at> haskell.org
Subject: Re: [Haskell-cafe] nice simple problem for someone struggling....

 

On Dec 21, 2007 11:50 AM, Nicholls, Mark <Nicholls.Mark <at> mtvne.com> wrote:

Now I have....

module Main where

data SquareType numberType = Num numberType => SquareConstructor
numberType


This is a valid declaration, but I don't think it does what you want it to. The constraint on numberType applies only to the data constructor.

That is, given an unknown value of type SquareType a for some a, we do not have enough information to infer Num a.

For your code, you want something like:

instance (Num a) => ShapeInterface (SquareType a) where
    area (SquareConstructor side) = side * side


--
Dave Menendez <dave <at> zednenem.com>
<http://www.eyrie.org/~zednenem/ >

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane