[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell
Subject:    Re: [Q] : fully defined type vs. class , as a result of function
From:       Sverker Nilsson <sverker () opq ! se>
Date:       1996-02-06 16:27:52
Message-ID: 199602061627.RAA27403 () animal ! cs ! chalmers ! se
[Download RAW message or body]


Hello,

I distinctly recall having run into similar problems to
Denis when I was myself beginning to try out the Haskell type system.

I still don't have the insight to tell what/if there is that
prohibits this, but intuitively I would say, it would just
be possible to loosen the type-checking a little bit??
Or would some major changes to the implementation be needed?

Denis Wallez <Denis.WALLEZ@enst-bretagne.fr> wrote:

> [snip]
> I started a little exemple like this:
> >class Derivable a where
> >   derive :: (Derivable b)=> a -> b
> I make the hypothesis that the result of derivation is still derivable,
> BUT not necessarily the same kind as the initial upper node value:
> (fg)'=(f'g)+(fg')    the upper node of tree is first a multiplication,
> but the second is an addition... no conservation.
> 
> >data Op_bin = Plus (Op_bin) (Op_bin)
> >            | Times (Op_bin) (Op_bin)
> 
> >instance Derivable Op_bin where
> >   derive (Plus a b) = Plus (derive a) (derive b) 
> >   derive (Times a b) = Plus (Times (derive a) b) (Times a (derive b))
> 

Incidentally, already this first instance gives an error when
I try to compile it on my Hugs system:

ERROR "tst.gs" (line 94): Declared type too general
*** Expression    : derive
*** Declared type : Op_bin -> a
*** Inferred type : Op_bin -> Op_bin

Interested in hearing more about this,

Sverker

PS. Rest of original message follows.


> This seem quite coherent. I thought I could then define
> data Op_1 = Val_int (Int)
>           | Val_var [Char]
>           | Val_float (Float)
> 
> instance Derivable Op_1 where
>    derive (Val_var x) | x=="x" = Val_int 1
>                       | otherwise = Val_int 0
>    derive _ = Val_int 0
> 
> But no way to do this:
> (with HUGS, which is declared fully implementing Haskell)
> 
> Reading script file "test4.hs":
> Type checking      
> ERROR "test4.hs" (line 8): Declared type too general
> *** Expression    : derive
> *** Declared type : Opbin -> a
> *** Inferred type : Opbin -> Opbin
> 
> This is not OK. If I make another class with a 'simplify' function,
> the result simplify(a+b)=(a+b) with no hypothesis on a and b, but
> symplify(1+2)=Val_int 3... so I NEED to make my declarations such as
> I can return ANY type in the class With_simplify. 
> Since the idea I had was to simplify the result of the naive derivation,
> before returning it (i.e. Op_bin should be also an instance of 
> With_simplify), I NEED the 'general' declaration for the derivation.
> 
> 
> How can I achieve this ?
> Does Haskell need ANYWAY a fully defined type when defining the
>  type of the result of a function ?
> If there's a way to round the difficulty, what is it, or do you have
> any pointer ?
> 
> Thanks a lot in advance.
> Denis.
> 
> Denis WALLEZ   --- TELECOM BRETAGNE \ 3A-IPR \ technopole Brest-Iroise 
> (98 00 18 12)  --- 29280 PLOUZANE        Denis.WALLEZ@enst-bretagne.fr
> fax 98 00 11 90 (preciser: "pour WALLEZ- 3A")
> Team Ada       --- e-mail >> fax >> phone
> 
> 
> ----- End Included Message -----
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic