Skip to content

Instantly share code, notes, and snippets.

@teh
Created January 17, 2017 10:09
Show Gist options
  • Save teh/737d9c63429b5a23908945bdb33541de to your computer and use it in GitHub Desktop.
Save teh/737d9c63429b5a23908945bdb33541de to your computer and use it in GitHub Desktop.
{-# 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