Hello,
I was hoping that someone could answer a question I have about the
type class system. In Haskell, I cannot write a term with an exact
constraint:
data X = X
bar :: Show X = X - String
bar x = show x
According to the Haskell 98 report, a qualifier can only be applied to
type variables,
with just applying show to it. There's no
need to actually assert that it's actually an instance of Show again.
The only purpose of class constraints is to restrict polymorphism. If
a function isn't polymorphic to begin with, you should never need
them.
- Cale
On 21/11/05, Paul Govereau
On Oct 12, John Meacham wrote:
[...]
class Num a where
(+), (*):: a - a - a
(-) :: a - a - a
negate :: a - a
fromInteger :: Integer - a
ideally we would want to split it up like so (but with more mathematically
precise names):
class Additive a
my original program was a case similar to this last one.
Thanks again for the quick response.
Paul
On Aug 05, Roberto Zunino wrote:
Paul Govereau wrote:
[snip]
instance AbSyn Constraint where
subst e n constr =
let sub = subst e n -- :: AbSyn a = a - a
in case constr
Hello,
I have encountered a type error that I find quite puzzling. I would
appreciate it if someone could help me understand what is going wrong.
Here is the program:
data Expr = Var String | Const Int
data Constraint = Zero Expr | AndL Constraint
class AbSyn a where
subst :: Expr -
This is a great example, thanks for posting it. However, I feel like
the real problem in this example is the lexically-scoped type
variables declared with your function f. I am always surprised by the
effects that lexically-scoped type variables can have on top-level
declarations.
Consider
I realize now that your original example did not actually have any
such type variables. While playing around with your puzzle, I managed
to introduce some. However, perhaps the lexically-scoped type
variables are interesting in their own right.
Sorry for the confusion,
--Paul
On Nov 24, Paul