Re: instance declaration troubles

2003-03-07 Thread Hal Daume III
See my Double Argh message, but other than that, the only way is if you
redefine your Functor class to be a subclass of Get, which means you need
to define your own and cannot use the library one (unless something like
superclass is adopted...there's a recommendation out there for this
somewhere).  You need undecidable instances because in general something
like this is not decidable.  The way that undecidable instances deals with
the problem is that it sets a depth for instance reduction and if this
depth is hit, it just dies.

That said, undecidable instances sound very scary, but they're really
not.  You can google around for a conversation I had with SPJ about this a
while back, but something being an und instance is a compile time
property.  That is, if compilation succeeds, you don't have anything to
worry about and the worst that can happen at compilation time is that
you'll hit the bottom of this stack.

--
 Hal Daume III   | [EMAIL PROTECTED]
 Arrest this man, he talks in maths.   | www.isi.edu/~hdaume

On Fri, 7 Mar 2003, Nick Name wrote:

 Yes, I usually RTFM before posting, but you have misunderstood my
 question (however, thanks for always reading and answering newbie
 questions like mine); what I want to do is the 
 
 instance (Get a) = Functor a where
  fmap f x = mk (ls x = return . map f)
 
 Now, what I mean is: any type in Get class is also in Functor class,
 and I tell you how. But I need undecidable instances! Why? Is there a
 simple way to state this property, that the Get class is a subset of the
 Functor class?
 
 Vincenzo
 
 
 ___
 Haskell-Cafe mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: instance declaration troubles

2003-03-07 Thread Nick Name
On Fri, 7 Mar 2003 07:47:09 -0800 (PST)
Hal Daume III [EMAIL PROTECTED] wrote:

 
  That said, undecidable instances sound very scary, but they're
  really not.  You can google around for a conversation I had with SPJ
  about this a while back, but something being an und instance is a
  compile time property.  That is, if compilation succeeds, you don't
  have anything to worry about and the worst that can happen at
  compilation time is that you'll hit the bottom of this stack.

Thanks, you've been clear, even I miss that in haskell98 one can't
define subset properties between type classes... maybe because that
would mean subtyping?

Vincenzo
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: instance declaration troubles

2003-03-07 Thread Simon Peyton-Jones
It's in 7.3.5.3.  I'm going to make it more prominent

S

| -Original Message-
| From: Hal Daume III [mailto:[EMAIL PROTECTED]
| Sent: 07 March 2003 15:08
| To: Nick Name
| Cc: Haskell Cafe
| Subject: RE: instance declaration troubles
| 
| Double Argh!  I just noticed that this isn't what I meant to quote and
now
| I can't find it.  But the basic idea of what I wanted to quote was
that:
| 
| YOu have to have at least one non-type variable in instance
declarations
| otherwise we don't necessarily know that reduction will terminate.
I.e.:
| 
|   instance A a = B a where
|   instance B a = A a where
| 
| will not terminate if you ever try to reduce A to B.  I recall from
the
| docs that Simon is looking for a rule which lifts this rule but still
| maintains decidability.  or something along those lines.
| 
| Sorry about that!
| 
|  - Hal
| 
| --
|  Hal Daume III   | [EMAIL PROTECTED]
|  Arrest this man, he talks in maths.   | www.isi.edu/~hdaume
| 
| On Fri, 7 Mar 2003, Simon Peyton-Jones wrote:
| 
|  Argh. The documentation is out of date, or rather, inconsistent.
| 
|  In Section 7.3.4 you'll see that GHC -fglasgow-exts lifts the
|  restriction that class methods must not constrain only the class
type
|  variable.
| 
|  I'll fix 7.3.5.2, which you are quoting.
| 
|  Simon
| 
|  | -Original Message-
|  | From: Hal Daume III [mailto:[EMAIL PROTECTED]
|  | Sent: 07 March 2003 03:16
|  | To: Nick Name
|  | Cc: [EMAIL PROTECTED]
|  | Subject: Re: instance declaration troubles
|  |
|  | From the GHC docs:
|  |
|  | In the signature of a class operation, every constraint must
mention
|  at
|  | least one type variable that is not a class type variable. Thus:
|  |
|  |   class Collection c a where
|  | mapC :: Collection c b = (a-b) - c a - c b
|  |
|  | is OK because the constraint (Collection a b) mentions b, even
though
|  it
|  | also mentions the class variable a. On the other hand:
|  |
|  |   class C a where
|  | op :: Eq a = (a,b) - (a,b)
|  |
|  | is not OK because the constraint (Eq a) mentions on the class type
|  | variable a, but not b. However, any such example is easily fixed
by
|  moving
|  | the offending context up to the superclass context:
|  |
|  |   class Eq a = C a where
|  | op ::(a,b) - (a,b)
|  |
|  | A yet more relaxed rule would allow the context of a class-op
|  signature to
|  | mention only class type variables. However, that conflicts with
Rule
|  | 1(b) for types above.
|  |
|  | --
|  |  Hal Daume III   | [EMAIL PROTECTED]
|  |  Arrest this man, he talks in maths.   |
www.isi.edu/~hdaume
|  |
|  | On Fri, 7 Mar 2003, Nick Name wrote:
|  |
|  | 
|  |  I want to declare the following:
|  | 
|  |  class Get a where
|  |  ls :: a b - IO [b]
|  |  mk :: IO [b] - a b
|  | 
|  |  instance (Get a) = Functor a where
|  |  fmap f x = mk (ls x = return . map f)
|  | 
|  | 
|  |  But to have ghc type everything, I have to turn on
-fglasgow-exts
|  |  -fallow-undecidable-instances -fallow-overlapping-instances.
|  | 
|  |  Is there a clean way to state that all types in my type class
are
|  also
|  |  in the Functor type class?
|  | 
|  |  If not, what is the problem?
|  | 
|  |  Vincenzo
|  |  ___
|  |  Haskell-Cafe mailing list
|  |  [EMAIL PROTECTED]
|  |  http://www.haskell.org/mailman/listinfo/haskell-cafe
|  | 
|  |
|  | ___
|  | Haskell-Cafe mailing list
|  | [EMAIL PROTECTED]
|  | http://www.haskell.org/mailman/listinfo/haskell-cafe
|  ___
|  Haskell-Cafe mailing list
|  [EMAIL PROTECTED]
|  http://www.haskell.org/mailman/listinfo/haskell-cafe
| 
| 
| ___
| Haskell-Cafe mailing list
| [EMAIL PROTECTED]
| http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


instance declaration troubles

2003-03-06 Thread Nick Name

I want to declare the following:

class Get a where
ls :: a b - IO [b]
mk :: IO [b] - a b

instance (Get a) = Functor a where
fmap f x = mk (ls x = return . map f)


But to have ghc type everything, I have to turn on -fglasgow-exts
-fallow-undecidable-instances -fallow-overlapping-instances.

Is there a clean way to state that all types in my type class are also
in the Functor type class? 

If not, what is the problem?

Vincenzo
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe