Implicit parameters

From HaskellWiki
Revision as of 14:03, 9 July 2016 by Dsf (talk | contribs) (Fix link to GHC doc)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The GHC manual on implicit parameters: [1].

Working example:

{-# LANGUAGE ImplicitParams #-}

import Data.List (sortBy)

sort   :: (?cmp :: a -> a -> Ordering) => [a] -> [a]
sort    = sortBy ?cmp

main = let ?cmp = compare in putStrLn (show (sort [3,1,2]))