Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active February 22, 2016 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danidiaz/3b9a6865686c777f328c to your computer and use it in GitHub Desktop.
Save danidiaz/3b9a6865686c777f328c to your computer and use it in GitHub Desktop.
Experiments with OverloadedLabels
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Main where
import GHC.OverloadedLabels
data Foo = Foo
{
_bar :: String
, _baz :: Int
}
-- https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields/OverloadedLabels
--
-- *Main> :t #baz
-- #baz :: IsLabel "baz" t => t
instance IsLabel "baz" (Foo -> Int) where
fromLabel _ = _baz
instance IsLabel "odd" (Foo -> Int) where
fromLabel _ = _baz
instance IsLabel "odd" (Foo -> String) where
fromLabel _ = _bar
fooval :: Foo
fooval = Foo "foo" 5
main :: IO ()
main = do
print (#baz fooval :: Int)
-- The following is a bit odd
print (#odd fooval :: Int)
print (#odd fooval :: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment