Felix Schroeter wrote:
> newtype IntFunnilyOrdered = IFO Int
> instance Ord IntFunnilyOrdered where compare ...
> int_from_ifo (IFO x) = x
> map int_from_ifo $ sort $ map IFO l
> Ideally, the compiler should figure out that map IFO and map
> int_from_ifo are essentially noops, except changing the class
> instances to use.
right. but i'd like to have an even more clever compiler,
in order to not have to write all those type coercions explicitely.
> If you use the instances once, I think using something like sortWith
> instead will be more elegant.
it depends. the design question then is
how to pass the argument (<=) to sort:
visibly (sortBy) or invisibly (as an Ord instance).
> foo = let
> instance Ord T where compare ... = ...
> in
> sort (something::[T])
> There's no Ord instance visible in the definition of sort.
i think there is (or should be). we have two different meanings of T here:
one is just T, the other is T with the Ord instance.
the last one should apply for the declaration of `something'
(because it is visible at that point).
perhaps this should better be written as
"type T' is instance Ord T where ..."
> somelist :: [T]
> somelist = let instance Ord T where ... in (generate some list of values in T)
the Ord instance here is local, and thus not available later in the program.
> sortedlist :: [T]
> sortedlist = let instance Ord T where [different from the above instance] in
> sort somelist
somelist's type is implicitely propagated from "just T" to
"T with the instance decl just given".
alternatively, we could require explicit propagation.
> That somehow twists my mind :-)
indeed, i'm not saying the proposal is fully thought out,
or easily implementable.
--
Dr. Johannes Waldmann Institut fur Informatik Universitat Leipzig
[EMAIL PROTECTED] http://www.informatik.uni-leipzig.de/~joe/
Augustusplatz, D-04109 Leipzig, Germany, Tel/Fax (+49) 341 97 32 204/209