27 Jun 12:54
possible OI extension
From: Serge D. Mechveliani <mechvel <at> botik.ru>
Subject: possible OI extension
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2008-06-27 10:55:45 GMT
Subject: possible OI extension
Newsgroups: gmane.comp.lang.haskell.glasgow.user
Date: 2008-06-27 10:55:45 GMT
Hello, people,
This is about possible extension in treating of overlapping instances.
Here is a simple example.
------------------------------------------
import qualified Data.Set as Set (empty, member, insert)
import List (nub)
class Nub a where myNub :: a -> a
instance Eq a => Nub [a] where myNub = nub
instance Ord a => Nub [a]
where
myNub xs = nub' Set.empty xs
where
nub' _ [] = []
nub' set (x: xs) = if Set.member x set then nub' set xs
else x: (nub' (Set.insert x set) xs)
------------------------------------------
The idea is that it is good to replace nub of the Haskell-98 library
with myNub.
Because:
for Eq a, myNub costs O(n^2),
for Ord a, myNub costs O(n*(log n)),
and it is good to denote this operation with the same name.
Compiling this by GHC under
(Continue reading)
RSS Feed