Implicit parameters
From HaskellWiki
(Difference between revisions)
(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]] | ||
[[Category:GHC]] | [[Category:GHC]] | ||
[[Category:Stub articles]] | [[Category:Stub articles]] | ||
Current revision
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]))
