Skip to content

Commit 8ee3c70

Browse files
committed
make pi-forall work on both: ghc 7.8.4 and 7.10.3, intial commit
1 parent 65632c2 commit 8ee3c70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+949
-180
lines changed

full/README renamed to full/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Features
2525
- bidirectional type checking
2626
- erased arguments (forall)
2727
- propositional equality
28-
- inductive & indexed datatypes
28+
- indexed datatypes
2929

3030
Not covered (Future work!)
3131
--------------------------
32-
- nontermination
32+
- termination & inductive datatypes
3333
- effects
3434
- co-induction
3535
- type inference & unification

full/pi-forall.cabal

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Author: Stephanie Weirich <[email protected]>, based on code by Trellys Tea
88
Maintainer: Stephanie Weirich <[email protected]>
99
Cabal-Version: >= 1.2
1010
Build-type: Simple
11-
tested-with: GHC == 7.6.3
11+
tested-with: GHC == 7.8.4, GHC == 7.10.3
1212

1313
library
1414
hs-source-dirs: src/
@@ -22,20 +22,17 @@ executable pi-forall
2222
hs-source-dirs: src/
2323
Main-is: Main.hs
2424
Build-depends: base >=4,
25-
parsec >= 3.1 && < 3.1.5,
25+
parsec (>= 3.1 && < 3.1.5) || (>= 3.1.8 && < 3.2),
2626
pretty >= 1.0.1.0,
27-
RepLib >= 0.5.3 && < 0.6,
28-
unbound >= 0.4.2 && < 0.5,
29-
mtl,
30-
-- 0.2.2.0, 0.3.0.0
27+
unbound-generics >= 0.2,
28+
mtl >= 2.2.1,
3129
transformers,
3230
array >= 0.3.0.2 && < 0.6,
3331
containers,
3432
directory,
3533
filepath,
3634
HUnit,
37-
QuickCheck,
38-
bimap == 0.2.4
35+
QuickCheck
3936
Ghc-Options: -Wall -fno-warn-unused-matches
4037

4138

full/src/Environment.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{- OPLSS -}
22

3-
{-# LANGUAGE GADTs, NamedFieldPuns, FlexibleContexts, ViewPatterns, RankNTypes #-}
3+
{-# LANGUAGE GADTs, NamedFieldPuns, FlexibleContexts, ViewPatterns, RankNTypes, CPP #-}
44
{-# OPTIONS_GHC -Wall -fno-warn-unused-matches #-}
55

66
-- | Utilities for managing a typechecking context.
@@ -21,13 +21,29 @@ module Environment
2121
import Syntax
2222
import PrettyPrint
2323

24-
import Unbound.LocallyNameless hiding (Data)
24+
import Unbound.Generics.LocallyNameless
2525

2626
import Text.PrettyPrint.HughesPJ
2727
import Text.ParserCombinators.Parsec.Pos(SourcePos)
2828
import Control.Monad.Reader
2929
import Control.Monad.Except
30+
31+
32+
33+
#ifdef MIN_VERSION_GLASGOW_HASKELL
34+
#if MIN_VERSION_GLASGOW_HASKELL(7,10,3,0)
35+
-- ghc >= 7.10.3
36+
#else
37+
-- older ghc versions, but MIN_VERSION_GLASGOW_HASKELL defined
38+
#endif
39+
#else
40+
-- MIN_VERSION_GLASGOW_HASKELL not even defined yet (ghc <= 7.8.x)
3041
import Data.Monoid
42+
#endif
43+
44+
45+
46+
3147

3248
import Data.List
3349
import Data.Maybe (listToMaybe, catMaybes)

full/src/Equal.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{- PiForall language, OPLSS -}
22

3-
{-# LANGUAGE ViewPatterns #-}
3+
{-# LANGUAGE ViewPatterns, FlexibleContexts, CPP #-}
44
{-# OPTIONS_GHC -Wall -fno-warn-unused-matches #-}
55

66
-- | Compare two terms for equality
@@ -12,9 +12,22 @@ module Equal (whnf, equate, ensurePi,
1212
import Syntax
1313
import Environment
1414

15-
import Unbound.LocallyNameless hiding (Data, Refl)
15+
import Unbound.Generics.LocallyNameless
1616
import Control.Monad.Except (catchError, zipWithM, zipWithM_)
17+
18+
19+
#ifdef MIN_VERSION_GLASGOW_HASKELL
20+
#if MIN_VERSION_GLASGOW_HASKELL(7,10,3,0)
21+
-- ghc >= 7.10.3
22+
#else
23+
-- older ghc versions, but MIN_VERSION_GLASGOW_HASKELL defined
24+
#endif
25+
#else
26+
-- MIN_VERSION_GLASGOW_HASKELL not even defined yet (ghc <= 7.8.x)
1727
import Control.Applicative ((<$>))
28+
#endif
29+
30+
1831

1932

2033
-- | compare two expressions for equality

full/src/LayoutToken.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
--
1919
-----------------------------------------------------------------------------
2020

21-
{-# LANGUAGE PolymorphicComponents, NoMonomorphismRestriction, KindSignatures #-}
21+
{-# LANGUAGE PolymorphicComponents, NoMonomorphismRestriction, KindSignatures, FlexibleContexts #-}
2222
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-do-bind -fno-warn-unused-matches #-}
2323

2424
module LayoutToken
@@ -744,20 +744,20 @@ makeTokenParser languageDef open sep close
744744
layoutBegin = (symbol open) <?> ("layout opening symbol ("++open++")")
745745

746746
layout p stop =
747-
(do { try layoutBegin; xs <- sepBy p (symbol ";")
748-
; layoutEnd <?> "explicit layout closing brace"
749-
; stop; return (xs)}) <|>
747+
(do { try layoutBegin; xs <- sepBy p (symbol ";")
748+
; layoutEnd <?> "explicit layout closing brace"
749+
; stop; return (xs)}) <|>
750750
(do { indent; xs <- align p stop; return xs})
751751

752752
align p stop = ormore <|> zero
753753
where zero = do { stop; option "" layoutSep; undent; return []}
754-
ormore = do { x <- p
755-
; whiteSpace
756-
; (do { try layoutSep; xs <- align p stop; return (x:xs)}) <|>
757-
(do { try layoutEnd; stop; return([x])}) <|>
758-
-- removing indentation happens automatically
759-
-- in function whiteSpace
760-
(do { stop; undent; return ([x])})}
754+
ormore = do { x <- p
755+
; whiteSpace
756+
; (do { try layoutSep; xs <- align p stop; return (x:xs)}) <|>
757+
(do { try layoutEnd; stop; return([x])}) <|>
758+
-- removing indentation happens automatically
759+
-- in function whiteSpace
760+
(do { stop; undent; return ([x])})}
761761

762762
whiteSpace =
763763
do { (col1,_,_) <- getInfo
@@ -779,7 +779,7 @@ makeTokenParser languageDef open sep close
779779
rev (s:ss) xs = rev ss (s++xs)
780780
in adjust (col2,p:ps,[])
781781
(cs,p:ps,_,GT) -> return ()
782-
}
782+
}
783783
getInfo :: forall (m :: * -> *) t t1.
784784
Monad m =>
785785
ParsecT t1 t m (Column, t, t1)

full/src/Modules.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{- PiForall language, OPLSS -}
22

3-
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleContexts, CPP #-}
44
{-# OPTIONS_GHC -Wall -fno-warn-unused-matches -fno-warn-orphans #-}
55

66
-- | Tools for working with multiple source files
@@ -10,7 +10,23 @@ import Syntax
1010
import Parser(parseModuleFile, parseModuleImports)
1111

1212
import Text.ParserCombinators.Parsec.Error
13+
14+
15+
#ifdef MIN_VERSION_GLASGOW_HASKELL
16+
#if MIN_VERSION_GLASGOW_HASKELL(7,10,3,0)
17+
-- ghc >= 7.10.3
18+
#else
19+
-- older ghc versions
1320
import Control.Applicative
21+
#endif
22+
#else
23+
-- MIN_VERSION_GLASGOW_HASKELL not even defined yet
24+
import Control.Applicative
25+
#endif
26+
27+
28+
29+
1430
import Control.Monad.Except
1531
import Control.Monad.State.Lazy
1632
import System.FilePath

full/src/Parser.hs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{- PiForall language, OPLSS -}
22

3-
{-# LANGUAGE PatternGuards, FlexibleInstances, FlexibleContexts, TupleSections, ExplicitForAll #-}
3+
{-# LANGUAGE PatternGuards, FlexibleInstances, FlexibleContexts, TupleSections, ExplicitForAll, CPP #-}
44
{-# OPTIONS_GHC -Wall -fno-warn-unused-matches -fno-warn-orphans #-}
55

66
-- | A parsec-based parser for the concrete syntax.
@@ -15,16 +15,35 @@ module Parser
1515

1616
import Syntax hiding (moduleImports)
1717

18-
import Unbound.LocallyNameless hiding (Data,Refl,Infix,join,name)
18+
import Unbound.Generics.LocallyNameless
1919

2020
import Text.Parsec hiding (State,Empty)
2121
import Text.Parsec.Expr(Operator(..),Assoc(..),buildExpressionParser)
2222
import qualified LayoutToken as Token
2323

2424
import Control.Monad.State.Lazy hiding (join)
25+
26+
27+
#ifdef MIN_VERSION_GLASGOW_HASKELL
28+
#if MIN_VERSION_GLASGOW_HASKELL(7,10,3,0)
29+
-- ghc >= 7.10.3
30+
#else
31+
-- older ghc versions, but MIN_VERSION_GLASGOW_HASKELL defined
32+
#endif
33+
#else
34+
-- MIN_VERSION_GLASGOW_HASKELL not even defined yet (ghc <= 7.8.x)
2535
import Control.Applicative ( (<$>), (<*>))
36+
#endif
37+
38+
39+
40+
41+
2642
import Control.Monad.Except hiding (join)
2743

44+
45+
46+
2847
import Data.List
2948
import qualified Data.Set as S
3049

@@ -158,7 +177,7 @@ trellysStyle = Token.LanguageDef
158177
, Token.nestedComments = True
159178
, Token.identStart = letter
160179
, Token.identLetter = alphaNum <|> oneOf "_'"
161-
, Token.opStart = oneOf ":!#$%&*+.,/<=>?@\\^|-"
180+
, Token.opStart = oneOf ":!#$%&*+.,/<=>?@\\^|-"
162181
, Token.opLetter = oneOf ":!#$%&*+.,/<=>?@\\^|-"
163182
, Token.caseSensitive = True
164183
, Token.reservedNames =

full/src/PrettyPrint.hs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
{- PiForall language, OPLSS -}
22

3-
{-# LANGUAGE TypeSynonymInstances,ExistentialQuantification,FlexibleInstances, UndecidableInstances, FlexibleContexts,
4-
ViewPatterns, DefaultSignatures
5-
#-}
3+
{-# LANGUAGE TypeSynonymInstances,ExistentialQuantification,FlexibleInstances, UndecidableInstances, ViewPatterns, DefaultSignatures, GeneralizedNewtypeDeriving, FlexibleContexts, CPP #-}
64
{-# OPTIONS_GHC -Wall -fno-warn-unused-matches -fno-warn-name-shadowing #-}
75

86
-- | A Pretty Printer.
97
module PrettyPrint(Disp(..), D(..)) where
108

9+
import Data.Typeable (Typeable)
10+
1111
import Syntax
12-
import Unbound.LocallyNameless hiding (empty,Data,Refl)
12+
import Unbound.Generics.LocallyNameless
13+
import Unbound.Generics.LocallyNameless.Internal.Fold (toListOf)
1314

1415
import Control.Monad.Identity
1516
import Control.Monad.Reader
1617
import Text.PrettyPrint as PP
1718
import Text.ParserCombinators.Parsec.Pos (SourcePos, sourceName, sourceLine, sourceColumn)
1819
import Text.ParserCombinators.Parsec.Error (ParseError)
19-
import Control.Applicative ((<$>), (<*>))
20+
21+
22+
#ifdef MIN_VERSION_GLASGOW_HASKELL
23+
#if MIN_VERSION_GLASGOW_HASKELL(7,10,3,0)
24+
-- ghc >= 7.10.3
25+
#else
26+
-- older ghc versions, but MIN_VERSION_GLASGOW_HASKELL defined
27+
#endif
28+
#else
29+
-- MIN_VERSION_GLASGOW_HASKELL not even defined yet (ghc <= 7.8.x)
30+
import Control.Applicative (Applicative(..), (<$>), (<*>))
31+
#endif
32+
33+
34+
35+
36+
37+
2038
import qualified Data.Set as S
2139

2240
-- | The 'Disp' class governs types which can be turned into 'Doc's
@@ -32,11 +50,11 @@ class Disp d where
3250

3351
cleverDisp :: (Display d, Alpha d) => d -> Doc
3452
cleverDisp d =
35-
runIdentity (runReaderT (display d) initDI)
53+
runReaderDispInfo (display d) initDI
3654

3755

3856
instance Disp Term
39-
instance Rep a => Disp (Name a)
57+
instance Typeable a => Disp (Name a)
4058
instance Disp Telescope
4159
instance Disp Pattern
4260
instance Disp Match
@@ -132,12 +150,12 @@ instance Disp ConstructorDef where
132150
--
133151
data DispInfo = DI
134152
{
135-
showAnnots :: Bool, -- ^ should we show the annotations?
153+
showAnnots :: Bool, -- ^ should we show the annotations?
136154
dispAvoid :: S.Set AnyName -- ^ names that have been used
137155
}
138156

139157

140-
instance LFresh (Reader DispInfo) where
158+
instance LFresh (ReaderDispInfo) where
141159
lfresh nm = do
142160
let s = name2String nm
143161
di <- ask;
@@ -152,7 +170,13 @@ instance LFresh (Reader DispInfo) where
152170
initDI :: DispInfo
153171
initDI = DI False S.empty
154172

155-
type M a = (ReaderT DispInfo Identity) a
173+
newtype ReaderDispInfo a = ReaderDispInfo (ReaderT DispInfo Identity a)
174+
deriving (Functor, Applicative, Monad, MonadReader DispInfo)
175+
176+
runReaderDispInfo :: ReaderDispInfo a -> DispInfo -> a
177+
runReaderDispInfo (ReaderDispInfo comp) = runReader comp
178+
179+
type M a = ReaderDispInfo a
156180

157181
-- | The 'Display' class is like the 'Disp' class. It qualifies
158182
-- types that can be turned into 'Doc'. The difference is that the
@@ -294,7 +318,7 @@ instance Display Term where
294318
da <- display (unembed a)
295319
dn <- display n
296320
db <- display b
297-
let lhs = if (n `elem` fv b) then
321+
let lhs = if (n `elem` toListOf fv b) then
298322
parens (dn <+> colon <+> da)
299323
else
300324
wraparg (unembed a) da
@@ -362,7 +386,7 @@ instance Display Term where
362386
dn <- display n
363387
db <- display b
364388
let lhs = mandatoryBindParens Erased $
365-
if (n `elem` fv b) then
389+
if (n `elem` toListOf fv b) then
366390
(dn <+> colon <+> da)
367391
else
368392
da
@@ -470,7 +494,7 @@ gatherBinders body = do
470494
return ([], db)
471495

472496
-- Assumes that all terms were opened safely earlier.
473-
instance Rep a => Display (Name a) where
497+
instance Typeable a => Display (Name a) where
474498
display n = return $ (text . name2String) n
475499

476500
instance Disp [Term] where

0 commit comments

Comments
 (0)