Subtyping
Ashley Yakeley
ashley@semantic.org
Sat, 18 Aug 2001 15:20:26 -0700
At 2001-08-18 06:15, Marcin 'Qrczak' Kowalczyk wrote:
>Later additions to the function would have to be restricted to match
>at least one constructor defined in the current module, to make the
>combined definition independent of the order of additions - modules
>are by nature unordered.
Agreed.
>And something more - this is not enough for
>unambiguous definition:
> -- Base definition
> foo :: SomeObject -> SomeObject -> Int
> foo _ _ = 0
> -- Module 1
> foo (SomeInt a) _ = 1
> -- Module 2
> foo _ (SomeString a) = 2
> -- Which argument is evaluated as the first?
> -- What is called for foo (SomeInt 0) (SomeString "")?
The first argument would take priority. So Haskell would assemble these
cases in this order:
foo (SomeInt a) _ = 1
foo _ (SomeString a) = 2
foo _ _ = 0
If Module 2 included Module 1, it could do this:
-- Module 2
foo _ (SomeString a) = 2
foo (SomeInt a) (SomeString a) = 2
In which case, the cases would be assembled in this order:
foo (SomeInt a) (SomeString a) = 2
foo (SomeInt a) _ = 1
foo _ (SomeString a) = 2
foo _ _ = 0
--
Ashley Yakeley, Seattle WA