Skip to content

Instantly share code, notes, and snippets.

@paf31
Created February 7, 2013 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paf31/4732408 to your computer and use it in GitHub Desktop.
Save paf31/4732408 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
module SiteswapTypes where
data Nothing
data Catch more
data Pause more
data N0
data NS n
class InsertAt from h to | from h -> to
instance InsertAt Nothing N0 (Catch Nothing)
instance InsertAt (Pause more) N0 (Catch more)
instance (InsertAt Nothing n inserted) => InsertAt Nothing (NS n) (Pause inserted)
instance (InsertAt more n inserted) => InsertAt (Catch more) (NS n) (Catch inserted)
instance (InsertAt more n inserted) => InsertAt (Pause more) (NS n) (Pause inserted)
class Transition from h to | from h -> to
instance Transition Nothing N0 Nothing
instance Transition (Pause more) N0 more
instance (InsertAt more n inserted) => Transition (Catch more) (NS n) inserted
data Repeat
data Throw h more
class Transitions from hs to | from hs -> to
instance Transitions from Repeat from
instance (Transition st1 h st2, Transitions st2 hs st3) => Transitions st1 (Throw h hs) st3
type S1 = Catch Nothing
type S3 = Catch S1
type S7 = Catch S3
type S11 = Catch (Catch (Pause (Catch Nothing)))
type S15 = Catch S7
type S21 = Catch (Pause (Catch (Pause (Catch Nothing))))
type S31 = Catch S15
type N1 = NS N0
type N2 = NS N1
type N3 = NS N2
type N4 = NS N3
type N5 = NS N4
type Cascade = Throw N3 Repeat
type Shower = Throw N5 (Throw N1 Repeat)
type FiveThreeOne = Throw N5 (Throw N3 (Throw N1 Repeat))
testTransition :: (Transition from h to) => from -> h -> to -> ()
testTransition _ _ _ = ()
testTransitions :: (Transitions from hs to) => from -> hs -> to -> ()
testTransitions _ _ _ = ()
testPattern :: (Transitions from hs from) => from -> hs -> ()
testPattern _ _ = ()
test1 = testTransition (undefined :: S7)
(undefined :: N3)
(undefined :: S7)
test2 = testTransition (undefined :: S21)
(undefined :: N1)
(undefined :: S11)
test3 = testTransition (undefined :: S11)
(undefined :: N5)
(undefined :: S21)
test4 = testPattern (undefined :: S7)
(undefined :: Cascade)
test5 = testPattern (undefined :: S11)
(undefined :: Shower)
test6 = testPattern (undefined :: S7)
(undefined :: FiveThreeOne)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment