Skip to content

Commit

Permalink
Add support for GHC 7.10 & base-4.8
Browse files Browse the repository at this point in the history
This add missing `Functor` & `Applicative` instances for `P` and
`Lex` (and `DocM`) monads needed for AMP compatibility.

The package version is minor-bumped to v1.0.2.0 since new instances were
added to the exposed API.

Moreover, a Hackage-compliant changelog file is added as
extra-source-files.
  • Loading branch information
hvr committed Jan 24, 2015
1 parent 3b57094 commit 24452f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Language/Haskell/ParseMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ module Language.Haskell.ParseMonad(

import Language.Haskell.Syntax(SrcLoc(..))
import Control.Applicative
import Control.Monad (ap, liftM)
import Data.Monoid
import Prelude

-- | The result of a parse.
data ParseResult a
Expand Down Expand Up @@ -111,6 +113,13 @@ runParserWithMode mode (P m) s = case m s 0 1 start [] mode of
runParser :: P a -> String -> ParseResult a
runParser = runParserWithMode defaultParseMode

instance Functor P where
fmap = liftM

instance Applicative P where
pure = return
(<*>) = ap

instance Monad P where
return a = P $ \_i _x _y _l s _m -> Ok s a
P m >>= k = P $ \i x y l s mode ->
Expand Down Expand Up @@ -156,6 +165,13 @@ popContext = P $ \_i _x _y _l stk _m ->

newtype Lex r a = Lex { runL :: (a -> P r) -> P r }

instance Functor (Lex r) where
fmap = liftM

instance Applicative (Lex r) where
pure = return
(<*>) = ap

instance Monad (Lex r) where
return a = Lex $ \k -> k a
Lex v >>= f = Lex $ \k -> v (\a -> runL (f a) k)
Expand Down
7 changes: 7 additions & 0 deletions Language/Haskell/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module Language.Haskell.Pretty (

import Language.Haskell.Syntax

import Control.Applicative (Applicative(..))
import Control.Monad (ap)

import qualified Text.PrettyPrint as P

infixl 5 $$$
Expand Down Expand Up @@ -91,6 +94,10 @@ newtype DocM s a = DocM (s -> a)
instance Functor (DocM s) where
fmap f xs = do x <- xs; return (f x)

instance Applicative (DocM s) where
pure = return
(<*>) = ap

instance Monad (DocM s) where
(>>=) = thenDocM
(>>) = then_DocM
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 1.0.2.0

- Add support for GHC 7.10 & base-4.8)

- Add missing `Functor` & `Applicative` instances for `P` and `Lex`
monads needed for AMP compatibility.
14 changes: 11 additions & 3 deletions haskell-src.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: haskell-src
version: 1.0.1.6
-- don't forget to update the changelog.md!
version: 1.0.2.0
license: BSD3
license-file: LICENSE
author: Simon Marlow, Sven Panne and Noel Winstanley
-- Maintained through https://github.com/haskell-pkg-janitors. Join us!
maintainer: Conrad Parker <[email protected]>
maintainer: Herbert Valerio Riedel <[email protected]>
bug-reports: https://github.com/haskell-pkg-janitors/haskell-src/issues
category: Language
synopsis: Support for manipulating Haskell source code
description:
Expand All @@ -16,11 +18,13 @@ description:
build-type: Simple
cabal-version: >=1.6

extra-source-files: changelog.md

flag split-base

source-repository head
type: git
location: git://github.com/haskell-pkg-janitors/haskell-src.git
location: https://github.com/haskell-pkg-janitors/haskell-src.git

library
exposed-modules:
Expand All @@ -30,10 +34,14 @@ library
Language.Haskell.Pretty,
Language.Haskell.Syntax,
Language.Haskell.ParseUtils

if flag(split-base)
build-depends: base >= 4 && < 5, syb, pretty, array
else
build-depends: base < 3

build-tools: happy

extensions: CPP
nhc98-options: -K11M
ghc-options: -Wall -O2

0 comments on commit 24452f1

Please sign in to comment.