lifted spine view

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses,
    FlexibleInstances, UndecidableInstances, ScopedTypeVariables,
    NoMonomorphismRestriction, DeriveTraversable, DeriveFoldable,
    DeriveFunctor, GADTs, KindSignatures, TypeOperators, 
    TemplateHaskell,  BangPatterns
 #-}
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-name-shadowing 
    -fwarn-monomorphism-restriction -fwarn-hi-shadowing
  #-}

module LiftedSpine where
import Test.HUnit

-- Lifted Type View 
newtype Id x = InID x 
newtype Char' x = InChar' Char
newtype Int' x = InInt' Int 
data List' a x = Nil' | Cons' (a x) (List' a x)
data Pair' a b x = InPair' (a x ) (b x)
data Tree' a x = Empty' | Node' (Tree' a x ) (a x) (Tree' a x)

data Type' :: ( * -> * ) -> * where 
  Id :: Type' Id 
  Char' :: Type' Char' 
  Int' :: Type' Int' 
  List' :: Type' a -> Type' (List' a)
  Pair' :: Type' a -> Type' b -> Type' (Pair' a b)
  Tree' :: Type' a -> Type' (Tree' a)

infixl 1 :->
data Typed' (f :: * -> *)  a = (f a) :-> (Type' f)


size :: forall (f :: * -> *)  (a :: *) . Typed' f a -> Int 
size (Nil' :-> (List' a' )) = 0 
size (Cons' x xs :-> List' a' ) =  
  size (xs :-> List' a') + size (x :-> a' )
2:1: Error: Unused LANGUAGE pragma
Found:
{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses,
FlexibleInstances, UndecidableInstances, ScopedTypeVariables,
NoMonomorphismRestriction, DeriveTraversable, DeriveFoldable,
DeriveFunctor, GADTs, KindSignatures, TypeOperators,
TemplateHaskell, BangPatterns #-}
Why not:
{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses,
FlexibleInstances, UndecidableInstances, ScopedTypeVariables,
NoMonomorphismRestriction, DeriveTraversable, DeriveFoldable,
DeriveFunctor, GADTs, KindSignatures, TypeOperators #-}
34:7: Warning: Redundant bracket
Found:
Nil' :-> (List' a')
Why not:
Nil' :-> List' a'