Difference between revisions of "Implicit parameters"
Jump to navigation
Jump to search
(link to ghc manual) |
|||
Line 1: | Line 1: | ||
The GHC manual on implicit parameters: [http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html#implicit-parameters]. |
The GHC manual on implicit parameters: [http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html#implicit-parameters]. |
||
+ | |||
+ | 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])) |
||
[[Category:Language extensions]] |
[[Category:Language extensions]] |
Revision as of 18:41, 18 December 2012
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]))