Skip to content

Instantly share code, notes, and snippets.

@teh

teh/contrived.hs

Created Jan 17, 2017
Embed
What would you like to do?
{-# 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