On 01-Jul-1998, Simon L Peyton Jones <[EMAIL PROTECTED]> wrote:
> However, on further reflection, I now think:
>
> in any case where ambiguity would not result
> the original class declaration should be re-formulated
>
> So, I now think that the existing rule (all class variabl
| >delete :: (Dictionary dict key dat) => key -> dict -> dict
|
| It would not *always* result in ambiguity. For example, consider
|
| instance Dictionary (MyDict dat) Int dat where ...
|
| f :: MyDict dat -> MyDit dat
| f d = delete (3::Int) d
|
| Here, the polymorphism
Simon PJ wrote:
> So, I now think that the existing rule (all class variables
> must appear in each class-operation type signature) is probably
> the right one, but on stylistic rather than technical grounds.
I feel very uneasy about this style of argument - a language
designed this way become
> | > > class (Eq key, Ord key) => Dictionary dict key dat where
> | > > delete :: key -> dict -> dict
> | ...
> | > the first error:
> | >
> | > Class type variable `dat' does not appear in method signature
> | > delete :: key -> dict -> dict
> | >
> | > Why does ghc expect tha
> Ok, I did not reconize this solution, it seems to me the (nearly) proper one.
> But why not write:
>
>class => Dictionary dict where
>delete :: (Eq key, Ord key) => key -> dict key dat -> dict key dat
>...
>
> So one could avoid multiparamter classes at all. The two types k
> > Actually I think you would be better off with a class like
> > this:
> >
> > class (Eq key, Ord key) => Dictionary dict key where
> > delete :: key -> dict dat -> dict dat
> > search :: key -> dict dat -> (key, SearchResult dat, dict dat)
> > searchList :: [key] -> dict dat -
> Actually I think you would be better off with a class like
> this:
>
> class (Eq key, Ord key) => Dictionary dict key where
> delete :: key -> dict dat -> dict dat
> search :: key -> dict dat -> (key, SearchResult dat, dict dat)
> searchList :: [key] -> dict dat -> ([(key,Searc
| > > class (Eq key, Ord key) => Dictionary dict key dat where
| > > delete :: key -> dict -> dict
| ...
| > the first error:
| >
| > Class type variable `dat' does not appear in method signature
| > delete :: key -> dict -> dict
| >
| > Why does ghc expect that I use all of the
> The ghc compiler complains about 2 type errors in the following code:
>
> > data SearchResult a = Found a | Fail
> >
> > class (Eq key, Ord key) => Dictionary dict key dat where
> > delete :: key -> dict -> dict
> > search :: key -> dict -> (key,SearchResult dat,dict)
> > searchL
You're right. The restriction is excessive. Thanks for pointing
this out. Probably we should only require that at least one
of the class variables is constrained.
Why even require this? (All x) => x -> x uses the class `All'
which restricts its argument not one whit. -- P
10 matches
Mail list logo