Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Created January 25, 2019 15:05
Show Gist options
  • Save Solonarv/0bacab3e01713b73531d46ebd953d5aa to your computer and use it in GitHub Desktop.
Save Solonarv/0bacab3e01713b73531d46ebd953d5aa to your computer and use it in GitHub Desktop.
Simple named arguments, without reordering.
{-# 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