Difference between revisions of "Implicit parameters"

From HaskellWiki
Jump to navigation Jump to search
(fix link to ghc user guide)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{GHCUsersGuide|https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#implicit-parameters Implicit Parameters section}}
+
{{GHCUsersGuide|exts/implicit_parameters||an Implicit Parameters section}}
   
 
Working example:
 
Working example:

Latest revision as of 22:55, 12 June 2021

The GHC Users Guide has an Implicit Parameters section.

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]))