Last active
May 9, 2017 14:17
-
-
Save Philonous/637928bffd918ad5a6fcffb5f26a8d3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 TypeOperators #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE DataKinds #-} | |
module DTExample where | |
import Data.Singletons | |
import Data.Singletons.TH | |
import GHC.TypeLits | |
data AddressType = Private | Business | |
genSingletons [''AddressType] | |
type family AddressParts (a :: AddressType) :: * where | |
AddressParts Private = String -- Don't need an address | |
AddressParts Business = ( String | |
, Int -- e.g. House number | |
) -> String | |
makeAddress :: forall (at :: AddressType). Sing at -> AddressParts at | |
makeAddress at = | |
case at of | |
SPrivate -> "No address" | |
SBusiness -> \ (address, number) -> address ++ " #" ++ show number | |
test1 = makeAddress SPrivate | |
-- >>> "No address" | |
test3 = makeAddress SBusiness ("business1", 17) | |
-- "business1 #17" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment