Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[imp-dev] ints and reals and numbers

Hi guys,

Here's a discussion on a detail of the type system of PDB.values.

We used to have the Number type in PDB.values which we removed for
simplicity's sake (we deemed it unnecessary)
Number was the common supertype of int and real.

Now that we've started working with reals a lot at CWI we're
confronted with API design issues that would be solved if we had
Number back.

Example, some of our API looks like this now (in Rascal notation):
  void polygon(list[int] xs, list[int] ys)
  void polygon(list[real] xs, list[real] ys)

which does not allow arbitrary mixing of reals and ints as arguments
to polygon at all.
(unless we write void polygon(list[value] xs, list[value] ys), which
requires a lot of casting in the body of the function, leading to
possible run-time errors)

We'd rather have:
  void polygon(list[number] xs, list[number] ys)

Also, with functions with more arguments, API's tend to explode in
size to account for all possible combinations of int and real.

So, we'd love to put number back into the PDB type hierarchy. I
suspect that this would require breaking some API in pdb.values.

Another more general solution that is taken by many well designed
programming languages is to introduce "type classes" or "interfaces".
We have taken such a solution into consideration, only to conclude
that it introduces complexity where simplicity is more important:
  * PDB.values is a simple exchange format/API, not a programming language.
  * type classes/interfaces introduce "multiple inheritance", which
introduces more complicated error messages, complicated case
distinctions and generally harder-to-trace semantics.
  * it makes implementing the PDB API harder and harder, while it was
intended to abstract all kinds of data representations (such as
databases, YAML files, JSON, etc) rather easily.

Another hack is to do implicit coercions between ints and reals. We're
against such magic for too many reasons to mention.

So, Paul and I propose to reinstate number to its rightful position in
the type hierarchy. It will make our lives and our user's lives
easier.

Thanks!

Jurgen Vinju
Paul Klint

-- 
Jurgen Vinju
- Centrum Wiskunde & Informatica - SEN1
- INRIA Lille - ATEAMS
- Universiteit van Amsterdam

  www: http://jurgen.vinju.org,http://www.cwi.nl,
http://www.meta-environment.nl,http://twitter.com/jurgenvinju
skype: jurgen.vinju


Back to the top