Personal tools

Implicit parameters

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(link to ghc manual)
 
 
(2 intermediate revisions by one user not shown)

Latest revision as of 14:19, 9 July 2016

The GHC manual on implicit parameters: [1].

Working example:

{-# LANGUAGE ImplicitParams #-}

import Data.List (sortBy)

sortBy' :: (?cmp :: a -> a -> Ordering) => [a] -> [a]
sortBy' = sortBy ?cmp
sort :: Ord a => [a] -> [a]
sort = let ?cmp = compare in sortBy'

main = putStrLn (show (sort [3,1,2]))