In order to get around the problem of a type being able to have multiple
instances of the same class, I propose a new keyword, `instancetype'.
The
semantics of this keyword would fall somewhere between `type' and
`newtype'.
That is, it doesn't actually create a new type, but it isn't just an
alias
either.
As an example of what I'm getting at here, consider a sorted list:
> sortedInsert :: Ord a => [a] -> a -> [a]
Now, if a I have a data structure that looks something like this:
> data Employee = Employee {name :: String, salary :: Int, startDate :: Date}
How do I define Employee to be an instance of Ord? Here is what I'd like
to be
able to do:
> instancetype EmployeeByName = instance Ord EmployeeByName' where
> compare (Employee {name = x}) (Employee {name = y}) = compare x y
> instanceType EmployeeByName' = instance Eq Employee where
> (==) (Employee {name = x}) (Employee {name = y}) = x == y
> instancetype EmployeeBySalary = instance Ord EmployeeBySalary' where
> compare (Employee {salary = x}) (Employee {salary = y}) = compare x y
> instancetype EmployeeBySalary' = instance Eq Employee where
> (==) (Employee {salary = x}) (Employee {salary = y}) = x == y
> ...
> sortedInsert [] (employee :: EmployeeByName)
> sortedInsert payList (employee :: EmployeeBySalary)
On a different topic, I wouldn't mind seeing a ``standard'' foreign
function
interface defined for the language. I would like to have my programs
compile on
any ``Haskell 2 compliant'' compiler without having to go through
implementation-specific precompilers like Green Card. To make the
specification
simple, I think all that would need to be defined is a way to invoke a
library
routine. (No special in-line C code syntax, etc. However, callbacks
could be a
bear.)
I'm done now,
Michael Hobbs