archives

Modular Type Classes

by Derek Dreyer, Robert Harper, and Manuel M. T. Chakravarty

ML modules and Haskell type classes have proven to be highly effective tools for program structuring. Modules emphasize explicit configuration of program components and the use of data abstraction. Type classes emphasize implicit program construction and ad hoc polymorphism. In this paper, we show how the implicitly-typed style of type class programming may be supported within the framework of an explicitly-typed module language by viewing type classes as a particular mode of use of modules. This view offers a harmonious integration of modules and type classes, where type class features, such as class hierarchies and associated types, arise naturally as uses of existing module-language constructs, such as module hierarchies and type components. In addition, programmers have explicit control over which type class instances are available for use by type inference in a given scope. We formalize our approach as a Harper-Stone-style elaboration relation, and provide a sound type inference algorithm as a guide to implementation.

Higher order insertion sort - HELP PLZ

hi,

can someone help me out, i need the code for below 2 functions:

Question)Implement the higher order insertion sort algorithm hoInsertSort which
is similar to insertion sort except that an element x is placed before an
element y if fun x b is a function taken
as input by higher order insertion sort. In other words, the result of
evaluating hoInsertSort fun xs should be a list [y1,y2,..., yn] such
that
fun y1

-- Higher order insertion sort
-- Hint: first write a function hoins that inserts an element
-- in the right place
hoins :: Ord b => (a -> b) -> a -> [a] -> [a]
//add your code here

-- The function hoInsertionSort sorts a list

hoInsertionSort :: Ord b => (a -> b) -> [a] -> [a]
//add your code here