X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FExts.hs;h=7869c4788ac7b8935527eeb60a58e08823153d7e;hb=4aef249a45d1db6b300baa0b8d24179802062928;hp=52054565e377a268be729138c7d856bfd13a17e3;hpb=dc45583380f89ac23601aa9dc403956a82735bed;p=ghc-base.git diff --git a/GHC/Exts.hs b/GHC/Exts.hs index 5205456..7869c47 100644 --- a/GHC/Exts.hs +++ b/GHC/Exts.hs @@ -21,6 +21,8 @@ module GHC.Exts -- * Primitive operations module GHC.Prim, shiftL#, shiftRL#, iShiftL#, iShiftRA#, iShiftRL#, + uncheckedShiftL64#, uncheckedShiftRL64#, + uncheckedIShiftL64#, uncheckedIShiftRA64#, -- * Fusion build, augment, @@ -29,11 +31,14 @@ module GHC.Exts IsString(..), -- * Debugging - breakpoint, breakpointCond, Unknown, Unknown2, Unknown3, Unknown4, + breakpoint, breakpointCond, -- * Ids with special behaviour lazy, inline, + -- * Transform comprehensions + groupWith, sortWith, the + ) where import Prelude @@ -41,7 +46,28 @@ import Prelude import GHC.Prim import GHC.Base import GHC.Word +import GHC.Int import GHC.Num import GHC.Float import GHC.Ptr +import Data.String +import Data.List + +-- | 'the' ensures that all the elements of the list are identical +-- and then returns that unique element +the :: Eq a => [a] -> a +the (x:xs) + | all (x ==) xs = x + | otherwise = error "GHC.Exts.the: non-identical elements" +the [] = error "GHC.Exts.the: empty list" + +-- | The 'sortWith' function sorts a list of elements using the +-- user supplied function to project something out of each element +sortWith :: Ord b => (a -> b) -> [a] -> [a] +sortWith f = sortBy (\x y -> compare (f x) (f y)) +-- | The 'groupWith' function uses the user supplied function which +-- projects an element out of every list element in order to to first sort the +-- input list and then to form groups by equality on these projected elements +groupWith :: Ord b => (a -> b) -> [a] -> [[a]] +groupWith f = groupBy (\x y -> f x == f y) . sortWith f