Created
January 25, 2019 15:05
-
-
Save Solonarv/0bacab3e01713b73531d46ebd953d5aa to your computer and use it in GitHub Desktop.
Simple named arguments, without reordering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# language OverloadedLabels #-} -- other extensions omitted | |
import Data.Kind | |
import GHC.OverloadedLabels | |
import GHC.TypeLits | |
infix 1 ::# | |
data NamedType = Symbol ::# Type | |
data Tag (t :: NamedType) where Tag :: Tag t | |
instance IsLabel s (Tag t) where | |
fromLabel = Tag | |
infixr 0 -#> | |
type family (-#>) a b where | |
(-#>) (s ::# ty) b = Tag (s ::# ty) -> ty -> b | |
-- | example function | |
cylinderVol :: "height" ::# Double -#> "radius" ::# Double -#> Double | |
cylinderVol _ h _ r = h * pi * r * r | |
main = print $ cylinderVol #height 5 #radius 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment