[Haskell-beginners] A few really short beginners questions

Klaus Gy klausgy at gmail.com
Sun Oct 3 14:00:19 EDT 2010


Hi! I have a few questions to improve my knowledge of Haskell. I
didn't stumble over these problems while working on specific tasks, I
more or less constructed them explicitly to get an adequate
understanding of the basic Haskell semantics.

1

Why can't I apply a class directly to all instances of another,
existing class? For example why is it possible to write

  class Test a

  instance Num a => Test [a]

but not with

  instance Num a => Test a

in the last row?

2

Why is the following example not valid?

  f :: a -> a
  f '0' = 0
  f x = 1

I think the reason lies in the type system but I can't locate it exactly.

3

Why is the following legal

  [] :: Num a => [a]

but not with a self declared class instad of Num (unresolved overloading)?

4

Why does in the declaration

  f undefined = '0'

the expression undefined work apparently in the same way as a wildcard?

Thanks, fweth


More information about the Beginners mailing list