At 12:55 26-9-00 -0300, Prof. José Romildo Malaquias wrote:

[...skip...]
This solution works great for the data type, but, at least
to me, it seems to make it too dificult to write functions
over ExprExt.

Consider for example the original version of the addition
operation (somehow simplified) on the original Expr data type

  data Fn = Sum | Pro | Pow

  data Expr = Int Integer | Cte String | Var String | App Fn [Expr]

  add :: Expr -> Expr -> Expr
  add (Int x) (Int y) = Int (x + y)
  add (Int 0) x       = x
  add x       (Int 0) = x
  add x       y       = App Sum [x,y]

[...skip...]

The problem with this function definition is that it, if you would transform it using the scheme as I suggested earlier, returns results of different types depending on the *value* of the first argument. You can see this in the first two alternatives of add. If both arguments are of type INT, then the result is of type INT. If the first argument has value (INT 0) then the result has the same type as the second argument (which can be CTE, VAR, or APP). Basically, it is the same problem as giving a type to a function f which result type depends on its argument value:

f 0 = "Zero"
f 1 = 1.0
f 2 = '2'

I don't think this can be solved readily in Haskell. It sounds as if you need something like dynamic typing. I have added a reference [1] below (for Clean; anybody out here with refs to dynamics in Haskell?). In any case, that will not help you *right now*.

Finally, you remark:
The use of an existentialy quantified variable
would solve this,

  data Expr =                          Int Integer
            |                          Cte String
            |                          Var String
            | forall a . (FnExt fn) => App fn Expr

but would make it to difficult to extend the
data type with new value constructors.

I am not sure if this will really help you. This will bring you back to your initial problem: namely to extend constructors. In addition, the solution also relies on the class member functions of FnExt.

Regards,
Peter

--------------------------------------------------------------------------
[1] Pil, M.R.C. (1999), Dynamic types and type dependent functions, In Proc. of Implementation of Functional Languages (IFL '98), London, U.K., Hammond, Davie and Clack Eds., Springer-Verlag, Berlin, Lecture Notes in Computer Science 1595, pp 169-185.

Reply via email to