Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Created September 16, 2015 10:35
Show Gist options
  • Select an option

  • Save NicolasT/7ad255e9eca94be21315 to your computer and use it in GitHub Desktop.

Select an option

Save NicolasT/7ad255e9eca94be21315 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
module Langs where
import Data.Proxy
import GHC.TypeLits
data Language (code :: Symbol) where
English :: Language "en"
Dutch :: Language "nl"
French :: Language "fr"
deriving instance Show (Language code)
doSomething :: forall code. KnownSymbol code => Language code -> String
doSomething lang = "The code for " ++ show lang ++ " is " ++ show code
where
code = symbolVal (Proxy :: Proxy code)
main :: IO ()
main = do
putStrLn $ doSomething Dutch
putStrLn $ doSomething English
@dmjio
Copy link
Copy Markdown

dmjio commented Sep 16, 2015

Hot, I'm adding this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment