Created
January 17, 2017 10:09
-
-
Save teh/737d9c63429b5a23908945bdb33541de to your computer and use it in GitHub Desktop.
This file contains 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 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