{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE TypeOperators #-} | |
import GHC.Base (Type) | |
data Nil = Nil | |
data a :<> b = a :<> b | |
infixr 8 :<> | |
class Score (a :: [Type]) where | |
type Input a :: Type | |
score :: Input a -> Int | |
instance forall rest a. (Score rest) => Score (a ': rest) where | |
type Input (a ': rest) = Int :<> Input rest | |
score (s :<> rest) = s + score @rest rest | |
instance Score '[] where | |
type Input '[] = Nil | |
score Nil = 0 | |
-- λ score @'[Int, Bool] (1 :<> 2 :<> Nil) | |
-- 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment