Closed int-index closed 7 years ago
Since you're using TypeApplications which requires GHC >= 8.0.1, why not go all the way and remove the empty data declarations?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE KindSignatures #-}
import GHC.TypeLits
import Numeric (showIntAtBase)
import Data.Char (intToDigit, chr)
class Foo (a :: Symbol) r where
foo :: r
instance Foo "Bar" Int where
foo = 42
instance Foo "Baz" String where
foo = showIntAtBase 13 intToDigit (6*9) ""
instance Foo "Qux" Char where
foo = chr (foo @"Bar")
answer :: Int
answer = foo @"Bar"
thisWasntIt :: String
thisWasntIt = foo @"Baz"
orWasAdamsBeingCheeky :: Char
orWasAdamsBeingCheeky = foo @"Qux"
You can use Symbol
-kinded labels since Ether supports poly-kinds. But there's no way I'm declaring this as the official way to use the lib. I have argued against Symbol
labels on multiple occasions:
Can be replaced with
TypeApplications
andAllowAmbiguousTypes
: