git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'upstream/master' into pure11
commit2c0c2abb3a5f03b1993f860223fc4e9082880bd5 authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 17 Mar 2016, 22:05 (11 years ago) parent7591176546809c
81 files changed+1018−931
.travis.yml+3−18 CONTRIBUTORS.md+1 INSTALL.md+4−8 bundle/winbuild.sh+2−2 examples/failing/ConstraintInference.purs+10 examples/failing/OperatorSections.purs+8 examples/passing/ConstraintInference.purs+7 examples/passing/ContextSimplification.purs+13 examples/passing/MonadState.purs+32−19 psc-bundle/Main.hs+4−4 psc-ide-client/Main.hs+6−7 psc-ide-server/Main.hs+35−22 psc/Main.hs+2−2 psci/PSCi.hs+1−1 purescript.cabal+12−13 src/Control/Monad/Supply.hs+1−1 src/Language/PureScript/AST.hs+4−14 src/Language/PureScript/AST/Binders.hs+7−24 src/Language/PureScript/AST/Declarations.hs+4−24 src/Language/PureScript/CoreFn/Literals.hs → src/Language/PureScript/AST/Literals.hs+2−2 src/Language/PureScript/AST/Traversals.hs+195−105 src/Language/PureScript/Bundle.hs+3−3 src/Language/PureScript/CodeGen/JS.hs+2−2 src/Language/PureScript/CodeGen/JS/AST.hs+1−1 src/Language/PureScript/CodeGen/JS/Optimizer.hs+2−2 src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+1−1 src/Language/PureScript/CoreFn.hs+3−14 src/Language/PureScript/CoreFn/Binders.hs+1−1 src/Language/PureScript/CoreFn/Desugar.hs+6−26 src/Language/PureScript/CoreFn/Expr.hs+1−1 src/Language/PureScript/CoreFn/Traversals.hs+3−14 src/Language/PureScript/Docs/AsMarkdown.hs+1−2 src/Language/PureScript/Docs/Convert.hs+6−6 src/Language/PureScript/Docs/Convert/ReExports.hs+13−22 src/Language/PureScript/Docs/ParseAndBookmark.hs+2−2 src/Language/PureScript/Errors.hs+23−16 src/Language/PureScript/Ide.hs+3−3 src/Language/PureScript/Ide/CaseSplit.hs+1−10 src/Language/PureScript/Ide/Completion.hs+4−4 src/Language/PureScript/Ide/Error.hs+11−12 src/Language/PureScript/Ide/Externs.hs+1−1 src/Language/PureScript/Ide/Matcher.hs+6−6 src/Language/PureScript/Ide/Pursuit.hs+11−11 src/Language/PureScript/Ide/Reexports.hs+21−19 src/Language/PureScript/Ide/SourceFile.hs+40−40 src/Language/PureScript/Ide/State.hs+10−10 src/Language/PureScript/Ide/Types.hs+76−78 src/Language/PureScript/Kinds.hs+1−1 src/Language/PureScript/Linter.hs+1−1 src/Language/PureScript/Linter/Exhaustive.hs+17−14 src/Language/PureScript/Linter/Imports.hs+9−8 src/Language/PureScript/Make.hs+4−1 src/Language/PureScript/Parser/Declarations.hs+28−37 src/Language/PureScript/Parser/JS.hs+1−1 src/Language/PureScript/Pretty/Values.hs+48−31 src/Language/PureScript/Publish/ErrorsWarnings.hs+1−1 src/Language/PureScript/Sugar.hs+1−1 src/Language/PureScript/Sugar/BindingGroups.hs+3−3 src/Language/PureScript/Sugar/CaseDeclarations.hs+6−6 src/Language/PureScript/Sugar/DoNotation.hs+2−2 src/Language/PureScript/Sugar/Names.hs+4−4 src/Language/PureScript/Sugar/Names/Exports.hs+3−3 src/Language/PureScript/Sugar/Names/Imports.hs+4−4 src/Language/PureScript/Sugar/ObjectWildcards.hs+6−2 src/Language/PureScript/Sugar/Operators.hs+9−6 src/Language/PureScript/Sugar/TypeClasses.hs+5−5 src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+55−35 src/Language/PureScript/Sugar/TypeDeclarations.hs+1−1 src/Language/PureScript/TypeChecker.hs+12−12 src/Language/PureScript/TypeChecker/Entailment.hs+81−32 src/Language/PureScript/TypeChecker/Kinds.hs+11−11 src/Language/PureScript/TypeChecker/Monad.hs+15−15 src/Language/PureScript/TypeChecker/Rows.hs+1−1 src/Language/PureScript/TypeChecker/Skolems.hs+1−1 src/Language/PureScript/TypeChecker/Subsumption.hs+2−2 src/Language/PureScript/TypeChecker/Synonyms.hs+1−1 src/Language/PureScript/TypeChecker/Types.hs+72−90 src/Language/PureScript/TypeChecker/Unify.hs+6−5 src/Language/PureScript/Types.hs+2−2 stack-lts-2.yaml−13 stack-lts-3.yaml−6
.travis.yml+3−18
@@ -1,32 +1,17 @@
11language: c
2−sudo: false
2+dist: trusty
3+sudo: required
34matrix:
45 include:
5− - env: GHCVER=7.8.4 CABALVER=1.22 COVERAGE=true
6− compiler: ": #GHC 7.8.4 - tests"
7− # ^ HACK before https://github.com/travis-ci/travis-ci/issues/4393 is resolved
8− addons: {apt: {packages: [cabal-install-1.22,ghc-7.8.4,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
9− - env: GHCVER=7.6.3 CABALVER=1.22
10− compiler: ": #GHC 7.6.3"
11− addons: {apt: {packages: [cabal-install-1.22,ghc-7.6.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
12− - env: GHCVER=7.10.1 CABALVER=1.22 DEPLOY=yes
13− compiler: ": #GHC 7.10.1"
14− addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
15− - env: GHCVER=7.10.2 CABALVER=1.22 STACKAGE=lts-3.22 RUNSDISTTESTS=YES
16− compiler: ": #GHC 7.10.2 lts-3.22"
17− addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.2,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
186 - env: GHCVER=7.10.3 CABALVER=1.22 STACKAGE=lts-5.4 RUNSDISTTESTS=YES
197 compiler: ": #GHC 7.10.3 lts-5.4"
208 addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
219 - env: GHCVER=7.10.3 CABALVER=1.22 STACKAGE=nightly-2016-02-25
2210 compiler: ": #GHC 7.10.3 nightly-2016-02-25"
2311 addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
24− - env: GHCVER=7.10.3 CABALVER=1.22
12+ - env: GHCVER=7.10.3 CABALVER=1.22 DEPLOY=yes
2513 compiler: ": #GHC 7.10.3"
2614 addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
27− - env: GHCVER=8.0.1 CABALVER=1.24
28− compiler: ": #GHC 8.0.1"
29− addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1,happy-1.19.5,alex-3.1.4], sources: [hvr-ghc]}}
3015before_install:
3116 - unset CC
3217 - export PATH="/opt/ghc/$GHCVER/bin:$PATH"
CONTRIBUTORS.md+1
@@ -9,6 +9,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
99- [@anthok88](https://github.com/anthoq88) - My existing contributions and all future contributions until further notice are Copyright anthoq88, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license
1010- [@ardumont](https://github.com/ardumont) (Antoine R. Dumont) My existing contributions and all future contributions until further notice are Copyright Antoine R. Dumont, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1111- [@aspidites](https://github.com/aspidites) (Edwin Marshall) My existing contributions and all future contributions until further notice are Copyright Edwin Marshall, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
12+- [@bagl](https://github.com/bagl) (Petr Vapenka) My existing contributions and all future contributions until further notice are Copyright Petr Vapenka, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1213- [@balajirrao](https://github.com/balajirrao) (Balaji Rao) - My existing contributions and all future contributions until further notice are Copyright Balaji Rao, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
1314- [@bergmark](https://github.com/bergmark) (Adam Bergmark) - My existing contributions and all future contributions until further notice are Copyright Adam Bergmark, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
1415- [@Bogdanp](https://github.com/Bogdanp) (Bogdan Paul Popa) My existing contributions and all future contributions until further notice are Copyright Bogdan Paul Popa, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
INSTALL.md+4−8
@@ -6,8 +6,8 @@ alternatively Stack Overflow.
66
77## Using prebuilt binaries
88
9−The prebuilt binaries are compiled with GHC 7.8.4, and therefore they should
10−run on any operating system supported by GHC 7.8.4, such as:
9+The prebuilt binaries are compiled with GHC 7.10.3, and therefore they should
10+run on any operating system supported by GHC 7.10.3, such as:
1111
1212* Windows 2000 or later,
1313* OS X 10.7 or later,
@@ -23,11 +23,11 @@ requirements.
2323
2424## Compiling from source
2525
26−GHC 7.6.1 or newer is required to compile from source. The easiest way is to
26+GHC 7.10.1 or newer is required to compile from source. The easiest way is to
2727use stack:
2828
2929```
30−$ stack install --resolver lts purescript
30+$ stack install --resolver=nightly purescript
3131```
3232
3333This will then copy the compiler and utilities into `~/.local/bin`.
@@ -39,10 +39,6 @@ If you don't have stack installed yet there are install instructions
3939If you don't have ghc installed yet, stack will prompt you to run `stack setup`
4040which will install ghc for you.
4141
42−The PureScript compiler has been known to run on OS X 10.6 when built with GHC
43−7.6.
44−
45−
4642## The "curses" library
4743
4844`psci` depends on the `curses` library (via the Haskell package `terminfo`). If
bundle/winbuild.sh+2−2
@@ -17,8 +17,8 @@ strip ../dist/build/psci/psci.exe
1717strip ../dist/build/psc-docs/psc-docs.exe
1818strip ../dist/build/psc-publish/psc-publish.exe
1919strip ../dist/build/psc-bundle/psc-bundle.exe
20−strip ../dist/build/psc-ide-server/psc-ide-server
21−strip ../dist/build/psc-ide-client/psc-ide-client
20+strip ../dist/build/psc-ide-server/psc-ide-server.exe
21+strip ../dist/build/psc-ide-client/psc-ide-client.exe
2222
2323# Copy files to staging directory
2424cp ../dist/build/psc/psc.exe build/purescript/
examples/failing/ConstraintInference.pursnew file+10
@@ -0,0 +1,10 @@
1+-- @shouldFailWith NoInstanceFound
2+
3+module Main where
4+
5+import Prelude
6+
7+spin :: forall a b. a -> b
8+spin x = spin x
9+
10+test = show <<< spin
examples/failing/OperatorSections.pursnew file+8
@@ -0,0 +1,8 @@
1+-- @shouldFailWith CannotApplyFunction
2+module Main where
3+
4+import Prelude
5+
6+main = do
7+ (true `not` _)
8+
examples/passing/ConstraintInference.pursnew file+7
@@ -0,0 +1,7 @@
1+module Main where
2+
3+import Prelude
4+
5+shout = Control.Monad.Eff.Console.log <<< (<> "!") <<< show
6+
7+main = shout "Done"
examples/passing/ContextSimplification.pursnew file+13
@@ -0,0 +1,13 @@
1+module Main where
2+
3+import Prelude
4+import Control.Monad.Eff.Console
5+
6+shout = log <<< (<> "!") <<< show
7+
8+-- Here, we should simplify the context so that only one Show
9+-- constraint is added.
10+usesShowTwice true = shout
11+usesShowTwice false = print
12+
13+main = usesShowTwice true "Done"
examples/passing/MonadState.purs+32−19
@@ -1,12 +1,16 @@
11module Main where
22
33import Prelude
4+import Control.Monad.Eff.Console
45
56data Tuple a b = Tuple a b
67
7−class MonadState s m where
8+instance showTuple :: (Show a, Show b) => Show (Tuple a b) where
9+ show (Tuple a b) = "(" <> show a <> ", " <> show b <> ")"
10+
11+class Monad m <= MonadState s m where
812 get :: m s
9− put :: s -> m {}
13+ put :: s -> m Unit
1014
1115data State s a = State (s -> Tuple s a)
1216
@@ -29,20 +33,29 @@ instance monadState :: Monad (State s)
2933
3034instance monadStateState :: MonadState s (State s) where
3135 get = State (\s -> Tuple s s)
32− put s = State (\_ -> Tuple s {})
33−
34−modify :: forall m s. (Prelude.Monad m, MonadState s m) => (s -> s) -> m {}
35−modify f = do
36− s <- get
37− put (f s)
38−
39−test :: Tuple String String
40−test = runState "" $ do
41− modify $ (++) "World!"
42− modify $ (++) "Hello, "
43− get
44−
45−main = do
46− let t1 = test
47− Control.Monad.Eff.Console.log "Done"
48−
36+ put s = State (\_ -> Tuple s unit)
37+
38+-- Without the call to same, the following strange (but correct, in the absence of
39+-- functional dependencies) type:
40+--
41+-- forall m t1 t2.
42+-- ( Bind m
43+-- , MonadState t1 m
44+-- , MonadState t2 m
45+-- ) => (t1 -> t2) -> m Unit
46+--
47+-- With the type hint, the inferred type is more sensible:
48+--
49+-- forall m t.
50+-- ( Bind m
51+-- , MonadState t m
52+-- ) => (t -> t) -> m Unit
53+modify f =
54+ do
55+ s <- get
56+ put (same f s)
57+ where
58+ same :: forall a. (a -> a) -> (a -> a)
59+ same = id
60+
61+main = print $ runState 0 (modify (+ 1))
psc-bundle/Main.hs+4−4
@@ -51,7 +51,7 @@ data Options = Options
5151 } deriving Show
5252
5353-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
54−guessModuleIdentifier :: (Applicative m, MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
54+guessModuleIdentifier :: (MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
5555guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory filename)) <$> guessModuleType (takeFileName filename)
5656 where
5757 guessModuleType "index.js" = pure Regular
@@ -61,7 +61,7 @@ guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory f
6161-- | The main application function.
6262-- This function parses the input files, performs dead code elimination, filters empty modules
6363-- and generates and prints the final Javascript bundle.
64−app :: (Applicative m, MonadError ErrorMessage m, MonadIO m) => Options -> m String
64+app :: (MonadError ErrorMessage m, MonadIO m) => Options -> m String
6565app Options{..} = do
6666 inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
6767 when (null inputFiles) . liftIO $ do
@@ -119,13 +119,13 @@ options = Options <$> some inputFile
119119 requirePath = strOption $
120120 short 'r'
121121 <> long "require-path"
122− <> Opts.value ""
123− <> help "The path prefix used in require() calls in the generated JavaScript"
122+ <> help "The path prefix used in require() calls in the generated JavaScript [deprecated]"
124123
125124-- | Make it go.
126125main :: IO ()
127126main = do
128127 opts <- execParser (info (version <*> helper <*> options) infoModList)
128+ when (optionsRequirePath opts /= Nothing) $ hPutStrLn stderr "The require-path option is deprecated and will be removed in PureScript 0.9."
129129 output <- runExceptT (app opts)
130130 case output of
131131 Left err -> do
psc-ide-client/Main.hs+6−7
@@ -5,7 +5,6 @@ import Prelude ()
55import Prelude.Compat
66
77import Control.Exception
8−import Data.Maybe (fromMaybe)
98import Data.Text (Text)
109import qualified Data.Text as T
1110import qualified Data.Text.IO as T
@@ -18,19 +17,19 @@ import System.IO
1817import qualified Paths_purescript as Paths
1918
2019data Options = Options
21− { optionsPort :: Maybe Int
22− }
20+ { optionsPort :: PortID
21+ }
2322
2423main :: IO ()
2524main = do
2625 Options port <- execParser opts
27− let port' = PortNumber . fromIntegral $ fromMaybe 4242 port
28− client port'
26+ client port
2927 where
3028 parser =
3129 Options <$>
32− optional (option auto (long "port" <> short 'p'))
33− opts = info (version <*> parser) mempty
30+ (PortNumber . fromIntegral <$>
31+ option auto (long "port" <> short 'p' <> value (4242 :: Integer)))
32+ opts = info (version <*> helper <*> parser) mempty
3433 version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
3534
3635client :: PortID -> IO ()
psc-ide-server/Main.hs+35−22
@@ -11,8 +11,9 @@ import Prelude.Compat
1111
1212import Control.Concurrent (forkFinally)
1313import Control.Concurrent.STM
14−import Control.Exception (bracketOnError)
14+import Control.Exception (bracketOnError, catchJust)
1515import Control.Monad
16+import Control.Monad.Error.Class
1617import "monad-logger" Control.Monad.Logger
1718import Control.Monad.Reader
1819import Control.Monad.Trans.Except
@@ -32,6 +33,7 @@ import Options.Applicative
3233import System.Directory
3334import System.FilePath
3435import System.IO
36+import System.IO.Error (isEOFError)
3537
3638import qualified Paths_purescript as Paths
3739
@@ -87,7 +89,7 @@ main = do
8789 (PortNumber . fromIntegral <$>
8890 option auto (long "port" <> short 'p' <> value (4242 :: Integer))) <*>
8991 switch (long "debug")
90− opts = info (version <*> parser) mempty
92+ opts = info (version <*> helper <*> parser) mempty
9193 version = abortOption
9294 (InfoMsg (showVersion Paths.version))
9395 (long "version" <> help "Show the version number")
@@ -101,32 +103,43 @@ startServer port env = withSocketsDo $ do
101103
102104 loop :: (PscIde m, MonadLogger m) => Socket -> m ()
103105 loop sock = do
104− (cmd,h) <- acceptCommand sock
105− case decodeT cmd of
106− Just cmd' -> do
107− result <- runExceptT (handleCommand cmd')
108− $(logDebug) ("Answer was: " <> T.pack (show result))
109− liftIO (hFlush stdout)
110− case result of
111− -- What function can I use to clean this up?
112− Right r -> liftIO $ T.hPutStrLn h (encodeT r)
113− Left err -> liftIO $ T.hPutStrLn h (encodeT err)
114− Nothing -> do
115− $(logDebug) ("Parsing the command failed. Command: " <> cmd)
116− liftIO $ do
117− T.hPutStrLn h (encodeT (GeneralError "Error parsing Command."))
118− hFlush stdout
119− liftIO (hClose h)
106+ accepted <- runExceptT $ acceptCommand sock
107+ case accepted of
108+ Left err -> $(logDebug) err
109+ Right (cmd, h) -> do
110+ case decodeT cmd of
111+ Just cmd' -> do
112+ result <- runExceptT (handleCommand cmd')
113+ $(logDebug) ("Answer was: " <> T.pack (show result))
114+ liftIO (hFlush stdout)
115+ case result of
116+ -- What function can I use to clean this up?
117+ Right r -> liftIO $ T.hPutStrLn h (encodeT r)
118+ Left err -> liftIO $ T.hPutStrLn h (encodeT err)
119+ Nothing -> do
120+ $(logDebug) ("Parsing the command failed. Command: " <> cmd)
121+ liftIO $ do
122+ T.hPutStrLn h (encodeT (GeneralError "Error parsing Command."))
123+ hFlush stdout
124+ liftIO (hClose h)
120125
121126
122−acceptCommand :: (Applicative m, MonadIO m, MonadLogger m)
127+acceptCommand :: (MonadIO m, MonadLogger m, MonadError T.Text m)
123128 => Socket -> m (T.Text, Handle)
124129acceptCommand sock = do
125130 h <- acceptConnection
126131 $(logDebug) "Accepted a connection"
127− cmd <- liftIO (T.hGetLine h)
128− $(logDebug) cmd
129− pure (cmd, h)
132+ cmd' <- liftIO (catchJust
133+ -- this means that the connection was
134+ -- terminated without receiving any input
135+ (\e -> if isEOFError e then Just () else Nothing)
136+ (Just <$> T.hGetLine h)
137+ (const (pure Nothing)))
138+ case cmd' of
139+ Nothing -> throwError "Connection was closed before any input arrived"
140+ Just cmd -> do
141+ $(logDebug) cmd
142+ pure (cmd, h)
130143 where
131144 acceptConnection = liftIO $ do
132145 (h,_,_) <- accept sock
psc/Main.hs+2−2
@@ -107,7 +107,7 @@ globWarningOnMisses warn = concatMapM globWithWarning
107107readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
108108readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readUTF8File inFile
109109
110−parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
110+parseInputs :: (MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
111111 => [(Either P.RebuildPolicy FilePath, String)]
112112 -> [(FilePath, P.ForeignJS)]
113113 -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
@@ -138,7 +138,7 @@ requirePath :: Parser (Maybe FilePath)
138138requirePath = optional $ strOption $
139139 short 'r'
140140 <> long "require-path"
141− <> help "The path prefix to use for require() calls in the generated JavaScript"
141+ <> help "The path prefix to use for require() calls in the generated JavaScript [deprecated]"
142142
143143noTco :: Parser Bool
144144noTco = switch $
psci/PSCi.hs+1−1
@@ -214,7 +214,7 @@ handleDecls :: [P.Declaration] -> PSCI ()
214214handleDecls ds = do
215215 st <- PSCI $ lift get
216216 let st' = updateLets ds st
217− let m = createTemporaryModule False st' (P.ObjectLiteral [])
217+ let m = createTemporaryModule False st' (P.Literal (P.ObjectLiteral []))
218218 e <- psciIO . runMake $ make st' [m]
219219 case e of
220220 Left err -> PSCI $ printErrors err
purescript.cabal+12−13
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.8.1.0
2+version: 0.8.2.0
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
@@ -17,7 +17,7 @@ author: Phil Freeman <paf31@cantab.net>,
1717 Harry Garrood <harry@garrood.me>,
1818 Christoph Hegemann <christoph.hegemann1337@gmail.com>
1919
20−tested-with: GHC==7.8.4, GHC==7.10.3, GHC==8.0.1
20+tested-with: GHC==7.10.3
2121
2222extra-source-files: examples/passing/*.purs
2323 , examples/failing/*.purs
@@ -36,8 +36,7 @@ extra-source-files: examples/passing/*.purs
3636 , tests/support/flattened/*.js
3737 , tests/support/psci/*.purs
3838 , stack.yaml
39− , stack-lts-2.yaml
40− , stack-lts-3.yaml
39+ , stack-lts-5.yaml
4140 , stack-nightly.yaml
4241 , README.md
4342 , INSTALL.md
@@ -50,7 +49,7 @@ source-repository head
5049 location: https://github.com/purescript/purescript.git
5150
5251library
53− build-depends: base >=4.6 && <5,
52+ build-depends: base >=4.8 && <5,
5453 base-compat >=0.6.0,
5554 lifted-base >= 0.2.3 && < 0.2.4,
5655 monad-control >= 1.0.0.0 && < 1.1,
@@ -97,6 +96,7 @@ library
9796 Language.PureScript.AST.Binders
9897 Language.PureScript.AST.Declarations
9998 Language.PureScript.AST.Operators
99+ Language.PureScript.AST.Literals
100100 Language.PureScript.AST.SourcePos
101101 Language.PureScript.AST.Traversals
102102 Language.PureScript.AST.Exported
@@ -135,7 +135,6 @@ library
135135 Language.PureScript.CoreFn.Binders
136136 Language.PureScript.CoreFn.Desugar
137137 Language.PureScript.CoreFn.Expr
138− Language.PureScript.CoreFn.Literals
139138 Language.PureScript.CoreFn.Meta
140139 Language.PureScript.CoreFn.Module
141140 Language.PureScript.CoreFn.Traversals
@@ -245,7 +244,7 @@ library
245244executable psc
246245 build-depends: base >=4 && <5, base-compat >=0.6.0,
247246 containers -any, directory -any, filepath -any,
248− mtl -any, optparse-applicative >= 0.10.0, parsec -any, purescript -any,
247+ mtl -any, optparse-applicative >= 0.12.1, parsec -any, purescript -any,
249248 time -any, transformers -any, transformers-compat -any, Glob >= 0.7 && < 0.8,
250249 aeson >= 0.8 && < 0.12, bytestring -any, utf8-string >= 1 && < 2
251250 main-is: Main.hs
@@ -256,7 +255,7 @@ executable psc
256255
257256executable psci
258257 build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
259− mtl -any, optparse-applicative >= 0.10.0, parsec -any,
258+ mtl -any, optparse-applicative >= 0.12.1, parsec -any,
260259 haskeline >= 0.7.0.0, purescript -any, transformers -any,
261260 transformers-compat -any, process -any, time -any, Glob -any, base-compat >=0.6.0,
262261 boxes >= 0.1.4 && < 0.2.0
@@ -279,7 +278,7 @@ executable psci
279278
280279executable psc-docs
281280 build-depends: base >=4 && <5, purescript -any,
282− optparse-applicative >= 0.10.0, process -any, mtl -any,
281+ optparse-applicative >= 0.12.1, process -any, mtl -any,
283282 split -any, ansi-wl-pprint -any, directory -any,
284283 filepath -any, Glob -any, transformers -any,
285284 transformers-compat -any
@@ -301,7 +300,7 @@ executable psc-publish
301300 ghc-options: -Wall -O2
302301
303302executable psc-hierarchy
304− build-depends: base >=4 && <5, purescript -any, optparse-applicative >= 0.10.0,
303+ build-depends: base >=4 && <5, purescript -any, optparse-applicative >= 0.12.1,
305304 process -any, mtl -any, parsec -any, filepath -any, directory -any,
306305 Glob -any
307306 main-is: Main.hs
@@ -322,7 +321,7 @@ executable psc-bundle
322321 mtl -any,
323322 transformers -any,
324323 transformers-compat -any,
325− optparse-applicative >= 0.10.0,
324+ optparse-applicative >= 0.12.1,
326325 Glob -any
327326 ghc-options: -Wall -O2
328327 hs-source-dirs: psc-bundle
@@ -340,7 +339,7 @@ executable psc-ide-server
340339 , transformers -any
341340 , transformers-compat -any
342341 , network -any
343− , optparse-applicative >= 0.10.0
342+ , optparse-applicative >= 0.12.1
344343 , stm -any
345344 , text -any
346345 , base-compat >=0.6.0
@@ -354,7 +353,7 @@ executable psc-ide-client
354353 build-depends: base >=4 && <5
355354 , mtl -any
356355 , text -any
357− , optparse-applicative >= 0.10.0
356+ , optparse-applicative >= 0.12.1
358357 , network -any
359358 , base-compat >=0.6.0
360359 ghc-options: -Wall -O2
src/Control/Monad/Supply.hs+1−1
@@ -27,7 +27,7 @@ import Control.Monad.Error.Class (MonadError(..))
2727import Control.Monad.Reader
2828import Control.Monad.Writer
2929
30−newtype SupplyT m a = SupplyT { unSupplyT :: StateT Integer m a }
30+newtype SupplyT m a = SupplyT { unSupplyT :: StateT Integer m a }
3131 deriving (Functor, Applicative, Monad, MonadTrans, MonadError e, MonadWriter w, MonadReader r)
3232
3333runSupplyT :: Integer -> SupplyT m a -> m (a, Integer)
src/Language/PureScript/AST.hs+4−14
@@ -1,24 +1,14 @@
1−-----------------------------------------------------------------------------
1+-- |
2+-- The initial PureScript AST
23--
3−-- Module : Language.PureScript.AST
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- | The initial PureScript AST
12−--
13−-----------------------------------------------------------------------------
14−
154module Language.PureScript.AST (
165 module AST
176) where
187
198import Language.PureScript.AST.Binders as AST
209import Language.PureScript.AST.Declarations as AST
10+import Language.PureScript.AST.Exported as AST
11+import Language.PureScript.AST.Literals as AST
2112import Language.PureScript.AST.Operators as AST
2213import Language.PureScript.AST.SourcePos as AST
2314import Language.PureScript.AST.Traversals as AST
24−import Language.PureScript.AST.Exported as AST
src/Language/PureScript/AST/Binders.hs+7−24
@@ -4,6 +4,7 @@
44module Language.PureScript.AST.Binders where
55
66import Language.PureScript.AST.SourcePos
7+import Language.PureScript.AST.Literals
78import Language.PureScript.Names
89import Language.PureScript.Comments
910import Language.PureScript.Types
@@ -17,21 +18,9 @@ data Binder
1718 --
1819 = NullBinder
1920 -- |
20− -- A binder which matches a boolean literal
21+ -- A binder which matches a literal
2122 --
22− | BooleanBinder Bool
23− -- |
24− -- A binder which matches a string literal
25− --
26− | StringBinder String
27− -- |
28− -- A binder which matches a character literal
29− --
30− | CharBinder Char
31− -- |
32− -- A binder which matches a numeric literal
33− --
34− | NumberBinder (Either Integer Double)
23+ | LiteralBinder (Literal Binder)
3524 -- |
3625 -- A binder which binds an identifier
3726 --
@@ -59,14 +48,6 @@ data Binder
5948 --
6049 | ParensInBinder Binder
6150 -- |
62− -- A binder which matches a record and binds its properties
63− --
64− | ObjectBinder [(String, Binder)]
65− -- |
66− -- A binder which matches an array and binds its elements
67− --
68− | ArrayBinder [Binder]
69− -- |
7051 -- A binder which binds its input to an identifier
7152 --
7253 | NamedBinder Ident Binder
@@ -86,13 +67,15 @@ data Binder
8667binderNames :: Binder -> [Ident]
8768binderNames = go []
8869 where
70+ go ns (LiteralBinder b) = lit ns b
8971 go ns (VarBinder name) = name : ns
9072 go ns (ConstructorBinder _ bs) = foldl go ns bs
9173 go ns (BinaryNoParensBinder b1 b2 b3) = foldl go ns [b1, b2, b3]
9274 go ns (ParensInBinder b) = go ns b
93− go ns (ObjectBinder bs) = foldl go ns (map snd bs)
94− go ns (ArrayBinder bs) = foldl go ns bs
9575 go ns (NamedBinder name b) = go (name : ns) b
9676 go ns (PositionedBinder _ _ b) = go ns b
9777 go ns (TypedBinder _ b) = go ns b
9878 go ns _ = ns
79+ lit ns (ObjectLiteral bs) = foldl go ns (map snd bs)
80+ lit ns (ArrayLiteral bs) = foldl go ns bs
81+ lit ns _ = ns
src/Language/PureScript/AST/Declarations.hs+4−24
@@ -19,6 +19,7 @@ import qualified Data.Map as M
1919import Control.Monad.Identity
2020
2121import Language.PureScript.AST.Binders
22+import Language.PureScript.AST.Literals
2223import Language.PureScript.AST.Operators
2324import Language.PureScript.AST.SourcePos
2425import Language.PureScript.Types
@@ -309,21 +310,9 @@ type Guard = Expr
309310--
310311data Expr
311312 -- |
312− -- A numeric literal
313+ -- A literal value
313314 --
314− = NumericLiteral (Either Integer Double)
315− -- |
316− -- A string literal
317− --
318− | StringLiteral String
319− -- |
320− -- A character literal
321− --
322− | CharLiteral Char
323− -- |
324− -- A boolean literal
325− --
326− | BooleanLiteral Bool
315+ = Literal (Literal Expr)
327316 -- |
328317 -- A prefix -, will be desugared
329318 --
@@ -342,19 +331,10 @@ data Expr
342331 --
343332 | Parens Expr
344333 -- |
345− -- Operator section. This will be removed during desugaring and replaced with a partially applied
346− -- operator or lambda to flip the arguments.
334+ -- Operator section. This will be removed during desugaring and replaced with lambda.
347335 --
348336 | OperatorSection Expr (Either Expr Expr)
349337 -- |
350− -- An array literal
351− --
352− | ArrayLiteral [Expr]
353− -- |
354− -- An object literal
355− --
356− | ObjectLiteral [(String, Expr)]
357− -- |
358338 -- An object property getter (e.g. `_.x`). This will be removed during
359339 -- desugaring and expanded into a lambda that reads a property from an object.
360340 --
src/Language/PureScript/CoreFn/Literals.hs → src/Language/PureScript/AST/Literals.hsrenamed+2−2
@@ -3,7 +3,7 @@
33-- |
44-- The core functional representation for literal values.
55--
6−module Language.PureScript.CoreFn.Literals where
6+module Language.PureScript.AST.Literals where
77
88-- |
99-- Data type for literal values. Parameterised so it can be used for Exprs and
@@ -34,4 +34,4 @@ data Literal a
3434 -- An object literal
3535 --
3636 | ObjectLiteral [(String, a)]
37− deriving (Show, Read, Functor)
37+ deriving (Eq, Ord, Show, Read, Functor)
src/Language/PureScript/AST/Traversals.hs+195−105
@@ -1,17 +1,8 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.AST.Traversals
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- | AST traversal helpers
12−--
13−-----------------------------------------------------------------------------
1+{-# LANGUAGE ScopedTypeVariables #-}
142
3+-- |
4+-- AST traversal helpers
5+--
156module Language.PureScript.AST.Traversals where
167
178import Prelude ()
@@ -26,15 +17,20 @@ import Control.Monad
2617import Control.Arrow ((***), (+++))
2718
2819import Language.PureScript.AST.Binders
20+import Language.PureScript.AST.Literals
2921import Language.PureScript.AST.Declarations
3022import Language.PureScript.Types
3123import Language.PureScript.Traversals
3224import Language.PureScript.Names
3325
34−everywhereOnValues :: (Declaration -> Declaration) ->
35− (Expr -> Expr) ->
36− (Binder -> Binder) ->
37− (Declaration -> Declaration, Expr -> Expr, Binder -> Binder)
26+everywhereOnValues
27+ :: (Declaration -> Declaration)
28+ -> (Expr -> Expr)
29+ -> (Binder -> Binder)
30+ -> ( Declaration -> Declaration
31+ , Expr -> Expr
32+ , Binder -> Binder
33+ )
3834everywhereOnValues f g h = (f', g', h')
3935 where
4036 f' :: Declaration -> Declaration
@@ -47,13 +43,12 @@ everywhereOnValues f g h = (f', g', h')
4743 f' other = f other
4844
4945 g' :: Expr -> Expr
46+ g' (Literal l) = g (Literal (lit g' l))
5047 g' (UnaryMinus v) = g (UnaryMinus (g' v))
5148 g' (BinaryNoParens op v1 v2) = g (BinaryNoParens (g' op) (g' v1) (g' v2))
5249 g' (Parens v) = g (Parens (g' v))
5350 g' (OperatorSection op (Left v)) = g (OperatorSection (g' op) (Left $ g' v))
5451 g' (OperatorSection op (Right v)) = g (OperatorSection (g' op) (Right $ g' v))
55− g' (ArrayLiteral vs) = g (ArrayLiteral (map g' vs))
56− g' (ObjectLiteral vs) = g (ObjectLiteral (map (fmap g') vs))
5752 g' (TypeClassDictionaryConstructorApp name v) = g (TypeClassDictionaryConstructorApp name (g' v))
5853 g' (Accessor prop v) = g (Accessor prop (g' v))
5954 g' (ObjectUpdate obj vs) = g (ObjectUpdate (g' obj) (map (fmap g') vs))
@@ -71,13 +66,17 @@ everywhereOnValues f g h = (f', g', h')
7166 h' (ConstructorBinder ctor bs) = h (ConstructorBinder ctor (map h' bs))
7267 h' (BinaryNoParensBinder b1 b2 b3) = h (BinaryNoParensBinder (h' b1) (h' b2) (h' b3))
7368 h' (ParensInBinder b) = h (ParensInBinder (h' b))
74− h' (ObjectBinder bs) = h (ObjectBinder (map (fmap h') bs))
75− h' (ArrayBinder bs) = h (ArrayBinder (map h' bs))
69+ h' (LiteralBinder l) = h (LiteralBinder (lit h' l))
7670 h' (NamedBinder name b) = h (NamedBinder name (h' b))
7771 h' (PositionedBinder pos com b) = h (PositionedBinder pos com (h' b))
7872 h' (TypedBinder t b) = h (TypedBinder t (h' b))
7973 h' other = h other
8074
75+ lit :: (a -> a) -> Literal a -> Literal a
76+ lit go (ArrayLiteral as) = ArrayLiteral (map go as)
77+ lit go (ObjectLiteral as) = ObjectLiteral (map (fmap go) as)
78+ lit _ other = other
79+
8180 handleCaseAlternative :: CaseAlternative -> CaseAlternative
8281 handleCaseAlternative ca =
8382 ca { caseAlternativeBinders = map h' (caseAlternativeBinders ca)
@@ -90,13 +89,20 @@ everywhereOnValues f g h = (f', g', h')
9089 handleDoNotationElement (DoNotationLet ds) = DoNotationLet (map f' ds)
9190 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com (handleDoNotationElement e)
9291
93−everywhereOnValuesTopDownM :: (Functor m, Applicative m, Monad m) =>
94− (Declaration -> m Declaration) ->
95− (Expr -> m Expr) ->
96− (Binder -> m Binder) ->
97− (Declaration -> m Declaration, Expr -> m Expr, Binder -> m Binder)
92+everywhereOnValuesTopDownM
93+ :: forall m
94+ . (Monad m)
95+ => (Declaration -> m Declaration)
96+ -> (Expr -> m Expr)
97+ -> (Binder -> m Binder)
98+ -> ( Declaration -> m Declaration
99+ , Expr -> m Expr
100+ , Binder -> m Binder
101+ )
98102everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
99103 where
104+
105+ f' :: Declaration -> m Declaration
100106 f' (DataBindingGroupDeclaration ds) = DataBindingGroupDeclaration <$> traverse (f' <=< f) ds
101107 f' (ValueDeclaration name nameKind bs val) = ValueDeclaration name nameKind <$> traverse (h' <=< h) bs <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
102108 f' (BindingGroupDeclaration ds) = BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> (g val >>= g')) ds
@@ -105,13 +111,13 @@ everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
105111 f' (PositionedDeclaration pos com d) = PositionedDeclaration pos com <$> (f d >>= f')
106112 f' other = f other
107113
114+ g' :: Expr -> m Expr
115+ g' (Literal l) = Literal <$> lit (g >=> g') l
108116 g' (UnaryMinus v) = UnaryMinus <$> (g v >>= g')
109117 g' (BinaryNoParens op v1 v2) = BinaryNoParens <$> (g op >>= g') <*> (g v1 >>= g') <*> (g v2 >>= g')
110118 g' (Parens v) = Parens <$> (g v >>= g')
111119 g' (OperatorSection op (Left v)) = OperatorSection <$> (g op >>= g') <*> (Left <$> (g v >>= g'))
112120 g' (OperatorSection op (Right v)) = OperatorSection <$> (g op >>= g') <*> (Right <$> (g v >>= g'))
113− g' (ArrayLiteral vs) = ArrayLiteral <$> traverse (g' <=< g) vs
114− g' (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g' <=< g)) vs
115121 g' (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> (g v >>= g')
116122 g' (Accessor prop v) = Accessor prop <$> (g v >>= g')
117123 g' (ObjectUpdate obj vs) = ObjectUpdate <$> (g obj >>= g') <*> traverse (sndM (g' <=< g)) vs
@@ -125,31 +131,47 @@ everywhereOnValuesTopDownM f g h = (f' <=< f, g' <=< g, h' <=< h)
125131 g' (PositionedValue pos com v) = PositionedValue pos com <$> (g v >>= g')
126132 g' other = g other
127133
134+ h' :: Binder -> m Binder
135+ h' (LiteralBinder l) = LiteralBinder <$> lit (h >=> h') l
128136 h' (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h' <=< h) bs
129137 h' (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> (h b1 >>= h') <*> (h b2 >>= h') <*> (h b3 >>= h')
130138 h' (ParensInBinder b) = ParensInBinder <$> (h b >>= h')
131− h' (ObjectBinder bs) = ObjectBinder <$> traverse (sndM (h' <=< h)) bs
132− h' (ArrayBinder bs) = ArrayBinder <$> traverse (h' <=< h) bs
133139 h' (NamedBinder name b) = NamedBinder name <$> (h b >>= h')
134140 h' (PositionedBinder pos com b) = PositionedBinder pos com <$> (h b >>= h')
135141 h' (TypedBinder t b) = TypedBinder t <$> (h b >>= h')
136142 h' other = h other
137143
138− handleCaseAlternative (CaseAlternative bs val) = CaseAlternative <$> traverse (h' <=< h) bs
139− <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
144+ lit :: (a -> m a) -> Literal a -> m (Literal a)
145+ lit go (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM go) as
146+ lit go (ArrayLiteral as) = ArrayLiteral <$> traverse go as
147+ lit _ other = pure other
148+
149+ handleCaseAlternative :: CaseAlternative -> m CaseAlternative
150+ handleCaseAlternative (CaseAlternative bs val) =
151+ CaseAlternative
152+ <$> traverse (h' <=< h) bs
153+ <*> eitherM (traverse (pairM (g' <=< g) (g' <=< g))) (g' <=< g) val
140154
155+ handleDoNotationElement :: DoNotationElement -> m DoNotationElement
141156 handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> (g' <=< g) v
142157 handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> (h' <=< h) b <*> (g' <=< g) v
143158 handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse (f' <=< f) ds
144159 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
145160
146−everywhereOnValuesM :: (Functor m, Applicative m, Monad m) =>
147− (Declaration -> m Declaration) ->
148− (Expr -> m Expr) ->
149− (Binder -> m Binder) ->
150− (Declaration -> m Declaration, Expr -> m Expr, Binder -> m Binder)
161+everywhereOnValuesM
162+ :: forall m
163+ . (Monad m)
164+ => (Declaration -> m Declaration)
165+ -> (Expr -> m Expr)
166+ -> (Binder -> m Binder)
167+ -> ( Declaration -> m Declaration
168+ , Expr -> m Expr
169+ , Binder -> m Binder
170+ )
151171everywhereOnValuesM f g h = (f', g', h')
152172 where
173+
174+ f' :: Declaration -> m Declaration
153175 f' (DataBindingGroupDeclaration ds) = (DataBindingGroupDeclaration <$> traverse f' ds) >>= f
154176 f' (ValueDeclaration name nameKind bs val) = (ValueDeclaration name nameKind <$> traverse h' bs <*> eitherM (traverse (pairM g' g')) g' val) >>= f
155177 f' (BindingGroupDeclaration ds) = (BindingGroupDeclaration <$> traverse (\(name, nameKind, val) -> (,,) name nameKind <$> g' val) ds) >>= f
@@ -158,13 +180,13 @@ everywhereOnValuesM f g h = (f', g', h')
158180 f' (PositionedDeclaration pos com d) = (PositionedDeclaration pos com <$> f' d) >>= f
159181 f' other = f other
160182
183+ g' :: Expr -> m Expr
184+ g' (Literal l) = (Literal <$> lit g' l) >>= g
161185 g' (UnaryMinus v) = (UnaryMinus <$> g' v) >>= g
162186 g' (BinaryNoParens op v1 v2) = (BinaryNoParens <$> g' op <*> g' v1 <*> g' v2) >>= g
163187 g' (Parens v) = (Parens <$> g' v) >>= g
164188 g' (OperatorSection op (Left v)) = (OperatorSection <$> g' op <*> (Left <$> g' v)) >>= g
165189 g' (OperatorSection op (Right v)) = (OperatorSection <$> g' op <*> (Right <$> g' v)) >>= g
166− g' (ArrayLiteral vs) = (ArrayLiteral <$> traverse g' vs) >>= g
167− g' (ObjectLiteral vs) = (ObjectLiteral <$> traverse (sndM g') vs) >>= g
168190 g' (TypeClassDictionaryConstructorApp name v) = (TypeClassDictionaryConstructorApp name <$> g' v) >>= g
169191 g' (Accessor prop v) = (Accessor prop <$> g' v) >>= g
170192 g' (ObjectUpdate obj vs) = (ObjectUpdate <$> g' obj <*> traverse (sndM g') vs) >>= g
@@ -178,33 +200,51 @@ everywhereOnValuesM f g h = (f', g', h')
178200 g' (PositionedValue pos com v) = (PositionedValue pos com <$> g' v) >>= g
179201 g' other = g other
180202
203+ h' :: Binder -> m Binder
204+ h' (LiteralBinder l) = (LiteralBinder <$> lit h' l) >>= h
181205 h' (ConstructorBinder ctor bs) = (ConstructorBinder ctor <$> traverse h' bs) >>= h
182206 h' (BinaryNoParensBinder b1 b2 b3) = (BinaryNoParensBinder <$> h' b1 <*> h' b2 <*> h' b3) >>= h
183207 h' (ParensInBinder b) = (ParensInBinder <$> h' b) >>= h
184− h' (ObjectBinder bs) = (ObjectBinder <$> traverse (sndM h') bs) >>= h
185− h' (ArrayBinder bs) = (ArrayBinder <$> traverse h' bs) >>= h
186208 h' (NamedBinder name b) = (NamedBinder name <$> h' b) >>= h
187209 h' (PositionedBinder pos com b) = (PositionedBinder pos com <$> h' b) >>= h
188210 h' (TypedBinder t b) = (TypedBinder t <$> h' b) >>= h
189211 h' other = h other
190212
191− handleCaseAlternative (CaseAlternative bs val) = CaseAlternative <$> traverse h' bs
192− <*> eitherM (traverse (pairM g' g')) g' val
213+ lit :: (a -> m a) -> Literal a -> m (Literal a)
214+ lit go (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM go) as
215+ lit go (ArrayLiteral as) = ArrayLiteral <$> traverse go as
216+ lit _ other = pure other
217+
218+ handleCaseAlternative :: CaseAlternative -> m CaseAlternative
219+ handleCaseAlternative (CaseAlternative bs val) =
220+ CaseAlternative
221+ <$> traverse h' bs
222+ <*> eitherM (traverse (pairM g' g')) g' val
193223
224+ handleDoNotationElement :: DoNotationElement -> m DoNotationElement
194225 handleDoNotationElement (DoNotationValue v) = DoNotationValue <$> g' v
195226 handleDoNotationElement (DoNotationBind b v) = DoNotationBind <$> h' b <*> g' v
196227 handleDoNotationElement (DoNotationLet ds) = DoNotationLet <$> traverse f' ds
197228 handleDoNotationElement (PositionedDoNotationElement pos com e) = PositionedDoNotationElement pos com <$> handleDoNotationElement e
198229
199−everythingOnValues :: (r -> r -> r) ->
200− (Declaration -> r) ->
201− (Expr -> r) ->
202− (Binder -> r) ->
203− (CaseAlternative -> r) ->
204− (DoNotationElement -> r) ->
205− (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r, DoNotationElement -> r)
230+everythingOnValues
231+ :: forall r
232+ . (r -> r -> r)
233+ -> (Declaration -> r)
234+ -> (Expr -> r)
235+ -> (Binder -> r)
236+ -> (CaseAlternative -> r)
237+ -> (DoNotationElement -> r)
238+ -> ( Declaration -> r
239+ , Expr -> r
240+ , Binder -> r
241+ , CaseAlternative -> r
242+ , DoNotationElement -> r
243+ )
206244everythingOnValues (<>) f g h i j = (f', g', h', i', j')
207245 where
246+
247+ f' :: Declaration -> r
208248 f' d@(DataBindingGroupDeclaration ds) = foldl (<>) (f d) (map f' ds)
209249 f' d@(ValueDeclaration _ _ bs (Right val)) = foldl (<>) (f d) (map h' bs) <> g' val
210250 f' d@(ValueDeclaration _ _ bs (Left gs)) = foldl (<>) (f d) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
@@ -214,13 +254,13 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
214254 f' d@(PositionedDeclaration _ _ d1) = f d <> f' d1
215255 f' d = f d
216256
257+ g' :: Expr -> r
258+ g' v@(Literal l) = lit (g v) g' l
217259 g' v@(UnaryMinus v1) = g v <> g' v1
218260 g' v@(BinaryNoParens op v1 v2) = g v <> g' op <> g' v1 <> g' v2
219261 g' v@(Parens v1) = g v <> g' v1
220262 g' v@(OperatorSection op (Left v1)) = g v <> g' op <> g' v1
221263 g' v@(OperatorSection op (Right v1)) = g v <> g' op <> g' v1
222− g' v@(ArrayLiteral vs) = foldl (<>) (g v) (map g' vs)
223− g' v@(ObjectLiteral vs) = foldl (<>) (g v) (map (g' . snd) vs)
224264 g' v@(TypeClassDictionaryConstructorApp _ v1) = g v <> g' v1
225265 g' v@(Accessor _ v1) = g v <> g' v1
226266 g' v@(ObjectUpdate obj vs) = foldl (<>) (g v <> g' obj) (map (g' . snd) vs)
@@ -234,42 +274,53 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
234274 g' v@(PositionedValue _ _ v1) = g v <> g' v1
235275 g' v = g v
236276
277+ h' :: Binder -> r
278+ h' b@(LiteralBinder l) = lit (h b) h' l
237279 h' b@(ConstructorBinder _ bs) = foldl (<>) (h b) (map h' bs)
238280 h' b@(BinaryNoParensBinder b1 b2 b3) = h b <> h' b1 <> h' b2 <> h' b3
239281 h' b@(ParensInBinder b1) = h b <> h' b1
240− h' b@(ObjectBinder bs) = foldl (<>) (h b) (map (h' . snd) bs)
241− h' b@(ArrayBinder bs) = foldl (<>) (h b) (map h' bs)
242282 h' b@(NamedBinder _ b1) = h b <> h' b1
243283 h' b@(PositionedBinder _ _ b1) = h b <> h' b1
244284 h' b@(TypedBinder _ b1) = h b <> h' b1
245285 h' b = h b
246286
287+ lit :: r -> (a -> r) -> Literal a -> r
288+ lit r go (ArrayLiteral as) = foldl (<>) r (map go as)
289+ lit r go (ObjectLiteral as) = foldl (<>) r (map (go . snd) as)
290+ lit r _ _ = r
291+
292+ i' :: CaseAlternative -> r
247293 i' ca@(CaseAlternative bs (Right val)) = foldl (<>) (i ca) (map h' bs) <> g' val
248294 i' ca@(CaseAlternative bs (Left gs)) = foldl (<>) (i ca) (map h' bs ++ concatMap (\(grd, val) -> [g' grd, g' val]) gs)
249295
296+ j' :: DoNotationElement -> r
250297 j' e@(DoNotationValue v) = j e <> g' v
251298 j' e@(DoNotationBind b v) = j e <> h' b <> g' v
252299 j' e@(DoNotationLet ds) = foldl (<>) (j e) (map f' ds)
253300 j' e@(PositionedDoNotationElement _ _ e1) = j e <> j' e1
254301
255−everythingWithContextOnValues ::
256− s ->
257− r ->
258− (r -> r -> r) ->
259− (s -> Declaration -> (s, r)) ->
260− (s -> Expr -> (s, r)) ->
261− (s -> Binder -> (s, r)) ->
262− (s -> CaseAlternative -> (s, r)) ->
263− (s -> DoNotationElement -> (s, r)) ->
264− ( Declaration -> r
265− , Expr -> r
266− , Binder -> r
267− , CaseAlternative -> r
268− , DoNotationElement -> r)
302+everythingWithContextOnValues
303+ :: forall s r
304+ . s
305+ -> r
306+ -> (r -> r -> r)
307+ -> (s -> Declaration -> (s, r))
308+ -> (s -> Expr -> (s, r))
309+ -> (s -> Binder -> (s, r))
310+ -> (s -> CaseAlternative -> (s, r))
311+ -> (s -> DoNotationElement -> (s, r))
312+ -> ( Declaration -> r
313+ , Expr -> r
314+ , Binder -> r
315+ , CaseAlternative -> r
316+ , DoNotationElement -> r)
269317everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
270318 where
319+
320+ f'' :: s -> Declaration -> r
271321 f'' s d = let (s', r) = f s d in r <> f' s' d
272322
323+ f' :: s -> Declaration -> r
273324 f' s (DataBindingGroupDeclaration ds) = foldl (<>) r0 (map (f'' s) ds)
274325 f' s (ValueDeclaration _ _ bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
275326 f' s (ValueDeclaration _ _ bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
@@ -279,15 +330,16 @@ everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'
279330 f' s (PositionedDeclaration _ _ d1) = f'' s d1
280331 f' _ _ = r0
281332
333+ g'' :: s -> Expr -> r
282334 g'' s v = let (s', r) = g s v in r <> g' s' v
283335
336+ g' :: s -> Expr -> r
337+ g' s (Literal l) = lit g'' s l
284338 g' s (UnaryMinus v1) = g'' s v1
285339 g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
286340 g' s (Parens v1) = g'' s v1
287341 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
288342 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
289− g' s (ArrayLiteral vs) = foldl (<>) r0 (map (g'' s) vs)
290− g' s (ObjectLiteral vs) = foldl (<>) r0 (map (g'' s . snd) vs)
291343 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
292344 g' s (Accessor _ v1) = g'' s v1
293345 g' s (ObjectUpdate obj vs) = foldl (<>) (g'' s obj) (map (g'' s . snd) vs)
@@ -301,42 +353,54 @@ everythingWithContextOnValues s0 r0 (<>) f g h i j = (f'' s0, g'' s0, h'' s0, i'
301353 g' s (PositionedValue _ _ v1) = g'' s v1
302354 g' _ _ = r0
303355
356+ h'' :: s -> Binder -> r
304357 h'' s b = let (s', r) = h s b in r <> h' s' b
305358
359+ h' :: s -> Binder -> r
360+ h' s (LiteralBinder l) = lit h'' s l
306361 h' s (ConstructorBinder _ bs) = foldl (<>) r0 (map (h'' s) bs)
307362 h' s (BinaryNoParensBinder b1 b2 b3) = h'' s b1 <> h'' s b2 <> h'' s b3
308363 h' s (ParensInBinder b) = h'' s b
309− h' s (ObjectBinder bs) = foldl (<>) r0 (map (h'' s . snd) bs)
310− h' s (ArrayBinder bs) = foldl (<>) r0 (map (h'' s) bs)
311364 h' s (NamedBinder _ b1) = h'' s b1
312365 h' s (PositionedBinder _ _ b1) = h'' s b1
313366 h' s (TypedBinder _ b1) = h'' s b1
314367 h' _ _ = r0
315368
369+ lit :: (s -> a -> r) -> s -> Literal a -> r
370+ lit go s (ArrayLiteral as) = foldl (<>) r0 (map (go s) as)
371+ lit go s (ObjectLiteral as) = foldl (<>) r0 (map (go s . snd) as)
372+ lit _ _ _ = r0
373+
374+ i'' :: s -> CaseAlternative -> r
316375 i'' s ca = let (s', r) = i s ca in r <> i' s' ca
317376
377+ i' :: s -> CaseAlternative -> r
318378 i' s (CaseAlternative bs (Right val)) = foldl (<>) r0 (map (h'' s) bs) <> g'' s val
319379 i' s (CaseAlternative bs (Left gs)) = foldl (<>) r0 (map (h'' s) bs ++ concatMap (\(grd, val) -> [g'' s grd, g'' s val]) gs)
320380
381+ j'' :: s -> DoNotationElement -> r
321382 j'' s e = let (s', r) = j s e in r <> j' s' e
322383
384+ j' :: s -> DoNotationElement -> r
323385 j' s (DoNotationValue v) = g'' s v
324386 j' s (DoNotationBind b v) = h'' s b <> g'' s v
325387 j' s (DoNotationLet ds) = foldl (<>) r0 (map (f'' s) ds)
326388 j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
327389
328−everywhereWithContextOnValuesM :: (Functor m, Applicative m, Monad m) =>
329− s ->
330− (s -> Declaration -> m (s, Declaration)) ->
331− (s -> Expr -> m (s, Expr)) ->
332− (s -> Binder -> m (s, Binder)) ->
333− (s -> CaseAlternative -> m (s, CaseAlternative)) ->
334− (s -> DoNotationElement -> m (s, DoNotationElement)) ->
335− ( Declaration -> m Declaration
336− , Expr -> m Expr
337− , Binder -> m Binder
338− , CaseAlternative -> m CaseAlternative
339− , DoNotationElement -> m DoNotationElement)
390+everywhereWithContextOnValuesM
391+ :: forall m s
392+ . (Monad m)
393+ => s
394+ -> (s -> Declaration -> m (s, Declaration))
395+ -> (s -> Expr -> m (s, Expr))
396+ -> (s -> Binder -> m (s, Binder))
397+ -> (s -> CaseAlternative -> m (s, CaseAlternative))
398+ -> (s -> DoNotationElement -> m (s, DoNotationElement))
399+ -> ( Declaration -> m Declaration
400+ , Expr -> m Expr
401+ , Binder -> m Binder
402+ , CaseAlternative -> m CaseAlternative
403+ , DoNotationElement -> m DoNotationElement)
340404everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j'' s0)
341405 where
342406 f'' s = uncurry f' <=< f s
@@ -351,13 +415,12 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
351415
352416 g'' s = uncurry g' <=< g s
353417
418+ g' s (Literal l) = Literal <$> lit g'' s l
354419 g' s (UnaryMinus v) = UnaryMinus <$> g'' s v
355420 g' s (BinaryNoParens op v1 v2) = BinaryNoParens <$> g'' s op <*> g'' s v1 <*> g'' s v2
356421 g' s (Parens v) = Parens <$> g'' s v
357422 g' s (OperatorSection op (Left v)) = OperatorSection <$> g'' s op <*> (Left <$> g'' s v)
358423 g' s (OperatorSection op (Right v)) = OperatorSection <$> g'' s op <*> (Right <$> g'' s v)
359− g' s (ArrayLiteral vs) = ArrayLiteral <$> traverse (g'' s) vs
360− g' s (ObjectLiteral vs) = ObjectLiteral <$> traverse (sndM (g'' s)) vs
361424 g' s (TypeClassDictionaryConstructorApp name v) = TypeClassDictionaryConstructorApp name <$> g'' s v
362425 g' s (Accessor prop v) = Accessor prop <$> g'' s v
363426 g' s (ObjectUpdate obj vs) = ObjectUpdate <$> g'' s obj <*> traverse (sndM (g'' s)) vs
@@ -373,16 +436,20 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
373436
374437 h'' s = uncurry h' <=< h s
375438
439+ h' s (LiteralBinder l) = LiteralBinder <$> lit h'' s l
376440 h' s (ConstructorBinder ctor bs) = ConstructorBinder ctor <$> traverse (h'' s) bs
377441 h' s (BinaryNoParensBinder b1 b2 b3) = BinaryNoParensBinder <$> h'' s b1 <*> h'' s b2 <*> h'' s b3
378442 h' s (ParensInBinder b) = ParensInBinder <$> h'' s b
379− h' s (ObjectBinder bs) = ObjectBinder <$> traverse (sndM (h'' s)) bs
380− h' s (ArrayBinder bs) = ArrayBinder <$> traverse (h'' s) bs
381443 h' s (NamedBinder name b) = NamedBinder name <$> h'' s b
382444 h' s (PositionedBinder pos com b) = PositionedBinder pos com <$> h'' s b
383445 h' s (TypedBinder t b) = TypedBinder t <$> h'' s b
384446 h' _ other = return other
385447
448+ lit :: (s -> a -> m a) -> s -> Literal a -> m (Literal a)
449+ lit go s (ArrayLiteral as) = ArrayLiteral <$> traverse (go s) as
450+ lit go s (ObjectLiteral as) = ObjectLiteral <$> traverse (sndM (go s)) as
451+ lit _ _ other = return other
452+
386453 i'' s = uncurry i' <=< i s
387454
388455 i' s (CaseAlternative bs val) = CaseAlternative <$> traverse (h'' s) bs <*> eitherM (traverse (pairM (g'' s) (g'' s))) (g'' s) val
@@ -394,25 +461,29 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
394461 j' s (DoNotationLet ds) = DoNotationLet <$> traverse (f'' s) ds
395462 j' s (PositionedDoNotationElement pos com e1) = PositionedDoNotationElement pos com <$> j'' s e1
396463
397−everythingWithScope ::
398− (Monoid r) =>
399− (S.Set Ident -> Declaration -> r) ->
400− (S.Set Ident -> Expr -> r) ->
401− (S.Set Ident -> Binder -> r) ->
402− (S.Set Ident -> CaseAlternative -> r) ->
403− (S.Set Ident -> DoNotationElement -> r) ->
404− ( S.Set Ident -> Declaration -> r
405− , S.Set Ident -> Expr -> r
406− , S.Set Ident -> Binder -> r
407− , S.Set Ident -> CaseAlternative -> r
408− , S.Set Ident -> DoNotationElement -> r)
464+everythingWithScope
465+ :: forall r
466+ . (Monoid r)
467+ => (S.Set Ident -> Declaration -> r)
468+ -> (S.Set Ident -> Expr -> r)
469+ -> (S.Set Ident -> Binder -> r)
470+ -> (S.Set Ident -> CaseAlternative -> r)
471+ -> (S.Set Ident -> DoNotationElement -> r)
472+ -> ( S.Set Ident -> Declaration -> r
473+ , S.Set Ident -> Expr -> r
474+ , S.Set Ident -> Binder -> r
475+ , S.Set Ident -> CaseAlternative -> r
476+ , S.Set Ident -> DoNotationElement -> r
477+ )
409478everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
410479 where
411480 -- Avoid importing Data.Monoid and getting shadowed names above
412481 (<>) = mappend
413482
483+ f'' :: S.Set Ident -> Declaration -> r
414484 f'' s a = f s a <> f' s a
415485
486+ f' :: S.Set Ident -> Declaration -> r
416487 f' s (DataBindingGroupDeclaration ds) =
417488 let s' = S.union s (S.fromList (mapMaybe getDeclIdent ds))
418489 in foldMap (f'' s') ds
@@ -431,15 +502,16 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
431502 f' s (PositionedDeclaration _ _ d) = f'' s d
432503 f' _ _ = mempty
433504
505+ g'' :: S.Set Ident -> Expr -> r
434506 g'' s a = g s a <> g' s a
435507
508+ g' :: S.Set Ident -> Expr -> r
509+ g' s (Literal l) = lit g'' s l
436510 g' s (UnaryMinus v1) = g'' s v1
437511 g' s (BinaryNoParens op v1 v2) = g' s op <> g' s v1 <> g' s v2
438512 g' s (Parens v1) = g'' s v1
439513 g' s (OperatorSection op (Left v)) = g'' s op <> g'' s v
440514 g' s (OperatorSection op (Right v)) = g'' s op <> g'' s v
441− g' s (ArrayLiteral vs) = foldMap (g'' s) vs
442− g' s (ObjectLiteral vs) = foldMap (g'' s . snd) vs
443515 g' s (TypeClassDictionaryConstructorApp _ v1) = g'' s v1
444516 g' s (Accessor _ v1) = g'' s v1
445517 g' s (ObjectUpdate obj vs) = g'' s obj <> foldMap (g'' s . snd) vs
@@ -460,20 +532,28 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
460532 g' s (PositionedValue _ _ v1) = g'' s v1
461533 g' _ _ = mempty
462534
535+ h'' :: S.Set Ident -> Binder -> r
463536 h'' s a = h s a <> h' s a
464537
538+ h' :: S.Set Ident -> Binder -> r
539+ h' s (LiteralBinder l) = lit h'' s l
465540 h' s (ConstructorBinder _ bs) = foldMap (h'' s) bs
466541 h' s (BinaryNoParensBinder b1 b2 b3) = foldMap (h'' s) [b1, b2, b3]
467542 h' s (ParensInBinder b) = h'' s b
468− h' s (ObjectBinder bs) = foldMap (h'' s . snd) bs
469− h' s (ArrayBinder bs) = foldMap (h'' s) bs
470543 h' s (NamedBinder name b1) = h'' (S.insert name s) b1
471544 h' s (PositionedBinder _ _ b1) = h'' s b1
472545 h' s (TypedBinder _ b1) = h'' s b1
473546 h' _ _ = mempty
474547
548+ lit :: (S.Set Ident -> a -> r) -> S.Set Ident -> Literal a -> r
549+ lit go s (ArrayLiteral as) = foldMap (go s) as
550+ lit go s (ObjectLiteral as) = foldMap (go s . snd) as
551+ lit _ _ _ = mempty
552+
553+ i'' :: S.Set Ident -> CaseAlternative -> r
475554 i'' s a = i s a <> i' s a
476555
556+ i' :: S.Set Ident -> CaseAlternative -> r
477557 i' s (CaseAlternative bs (Right val)) =
478558 let s' = S.union s (S.fromList (concatMap binderNames bs))
479559 in foldMap (h'' s) bs <> g'' s' val
@@ -481,8 +561,10 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
481561 let s' = S.union s (S.fromList (concatMap binderNames bs))
482562 in foldMap (h'' s) bs <> foldMap (\(grd, val) -> g'' s' grd <> g'' s' val) gs
483563
564+ j'' :: S.Set Ident -> DoNotationElement -> (S.Set Ident, r)
484565 j'' s a = let (s', r) = j' s a in (s', j s a <> r)
485566
567+ j' :: S.Set Ident -> DoNotationElement -> (S.Set Ident, r)
486568 j' s (DoNotationValue v) = (s, g'' s v)
487569 j' s (DoNotationBind b v) =
488570 let s' = S.union (S.fromList (binderNames b)) s
@@ -498,7 +580,15 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
498580 getDeclIdent (TypeDeclaration ident _) = Just ident
499581 getDeclIdent _ = Nothing
500582
501−accumTypes :: (Monoid r) => (Type -> r) -> (Declaration -> r, Expr -> r, Binder -> r, CaseAlternative -> r, DoNotationElement -> r)
583+accumTypes
584+ :: (Monoid r)
585+ => (Type -> r)
586+ -> ( Declaration -> r
587+ , Expr -> r
588+ , Binder -> r
589+ , CaseAlternative -> r
590+ , DoNotationElement -> r
591+ )
502592accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (const mempty) (const mempty)
503593 where
504594 forDecls (DataDeclaration _ _ _ dctors) = mconcat (concatMap (map f . snd) dctors)
src/Language/PureScript/Bundle.hs+3−3
@@ -141,7 +141,7 @@ checkImportPath :: Maybe FilePath -> String -> ModuleIdentifier -> S.Set String
141141checkImportPath _ "./foreign" m _ =
142142 Right (ModuleIdentifier (moduleName m) Foreign)
143143checkImportPath requirePath name _ names
144− | Just name' <- stripPrefix (fromMaybe "" requirePath) name
144+ | Just name' <- stripPrefix (fromMaybe "../" requirePath) name
145145 , name' `S.member` names = Right (ModuleIdentifier name' Regular)
146146checkImportPath _ name _ _ = Left name
147147
@@ -209,7 +209,7 @@ withDeps (Module modulePath es) = Module modulePath (map expandDeps es)
209209--
210210-- Each type of module element is matched using pattern guards, and everything else is bundled into the
211211-- Other constructor.
212−toModule :: forall m. (Applicative m, MonadError ErrorMessage m) => Maybe FilePath -> S.Set String -> ModuleIdentifier -> JSNode -> m Module
212+toModule :: forall m. (MonadError ErrorMessage m) => Maybe FilePath -> S.Set String -> ModuleIdentifier -> JSNode -> m Module
213213toModule requirePath mids mid top
214214 | JSSourceElementsTop ns <- node top = Module mid <$> traverse toModuleElement ns
215215 | otherwise = err InvalidTopLevel
@@ -533,7 +533,7 @@ codeGen optionsMainModule optionsNamespace ms = renderToString (NN (JSSourceElem
533533-- | The bundling function.
534534-- This function performs dead code elimination, filters empty modules
535535-- and generates and prints the final Javascript bundle.
536−bundle :: (Applicative m, MonadError ErrorMessage m)
536+bundle :: (MonadError ErrorMessage m)
537537 => [(ModuleIdentifier, String)] -- ^ The input modules. Each module should be javascript rendered from 'Language.PureScript.Make' or @psc@.
538538 -> [ModuleIdentifier] -- ^ Entry points. These module identifiers are used as the roots for dead-code elimination
539539 -> Maybe String -- ^ An optional main module.
src/Language/PureScript/CodeGen/JS.hs+2−2
@@ -47,7 +47,7 @@ import System.FilePath.Posix ((</>))
4747--
4848moduleToJs
4949 :: forall m
50− . (Applicative m, Monad m, MonadReader Options m, MonadSupply m, MonadError MultipleErrors m)
50+ . (Monad m, MonadReader Options m, MonadSupply m, MonadError MultipleErrors m)
5151 => Module Ann
5252 -> Maybe JS
5353 -> m [JS]
@@ -111,7 +111,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
111111 importToJs mnLookup mn' = do
112112 path <- asks optionsRequirePath
113113 let ((ss, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
114− let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (maybe id (</>) path $ runModuleName mn')]
114+ let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (fromMaybe ".." path </> runModuleName mn')]
115115 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
116116
117117 -- |
src/Language/PureScript/CodeGen/JS/AST.hs+1−1
@@ -347,7 +347,7 @@ everywhereOnJS f = go
347347everywhereOnJSTopDown :: (JS -> JS) -> JS -> JS
348348everywhereOnJSTopDown f = runIdentity . everywhereOnJSTopDownM (Identity . f)
349349
350−everywhereOnJSTopDownM :: (Applicative m, Monad m) => (JS -> m JS) -> JS -> m JS
350+everywhereOnJSTopDownM :: (Monad m) => (JS -> m JS) -> JS -> m JS
351351everywhereOnJSTopDownM f = f >=> go
352352 where
353353 f' = f >=> go
src/Language/PureScript/CodeGen/JS/Optimizer.hs+2−2
@@ -43,12 +43,12 @@ import Language.PureScript.CodeGen.JS.Optimizer.Blocks
4343-- |
4444-- Apply a series of optimizer passes to simplified Javascript code
4545--
46−optimize :: (Monad m, MonadReader Options m, Applicative m, MonadSupply m) => JS -> m JS
46+optimize :: (Monad m, MonadReader Options m, MonadSupply m) => JS -> m JS
4747optimize js = do
4848 noOpt <- asks optionsNoOptimizations
4949 if noOpt then return js else optimize' js
5050
51−optimize' :: (Monad m, MonadReader Options m, Applicative m, MonadSupply m) => JS -> m JS
51+optimize' :: (Monad m, MonadReader Options m, MonadSupply m) => JS -> m JS
5252optimize' js = do
5353 opts <- ask
5454 js' <- untilFixedPoint (inlineFnComposition . tidyUp . applyAll
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+1−1
@@ -235,7 +235,7 @@ inlineCommonOperators = applyAll $
235235
236236-- (f <<< g $ x) = f (g x)
237237-- (f <<< g) = \x -> f (g x)
238−inlineFnComposition :: (Applicative m, MonadSupply m) => JS -> m JS
238+inlineFnComposition :: (MonadSupply m) => JS -> m JS
239239inlineFnComposition = everywhereOnJSTopDownM convert
240240 where
241241 convert :: (MonadSupply m) => JS -> m JS
src/Language/PureScript/CoreFn.hs+3−14
@@ -1,17 +1,6 @@
1−-----------------------------------------------------------------------------
1+-- |
2+-- The core functional representation
23--
3−-- Module : Language.PureScript.CoreFn
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>, Gary Burgess <gary.burgess@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- | The core functional representation
12−--
13−-----------------------------------------------------------------------------
14−
154module Language.PureScript.CoreFn (
165 module C
176) where
@@ -20,7 +9,7 @@ import Language.PureScript.CoreFn.Ann as C
209import Language.PureScript.CoreFn.Binders as C
2110import Language.PureScript.CoreFn.Desugar as C
2211import Language.PureScript.CoreFn.Expr as C
23−import Language.PureScript.CoreFn.Literals as C
12+import Language.PureScript.AST.Literals as C
2413import Language.PureScript.CoreFn.Meta as C
2514import Language.PureScript.CoreFn.Module as C
2615import Language.PureScript.CoreFn.Traversals as C
src/Language/PureScript/CoreFn/Binders.hs+1−1
@@ -5,7 +5,7 @@
55--
66module Language.PureScript.CoreFn.Binders where
77
8−import Language.PureScript.CoreFn.Literals
8+import Language.PureScript.AST.Literals
99import Language.PureScript.Names
1010
1111-- |
src/Language/PureScript/CoreFn/Desugar.hs+6−26
@@ -17,7 +17,7 @@ import Language.PureScript.AST.Traversals
1717import Language.PureScript.CoreFn.Ann
1818import Language.PureScript.CoreFn.Binders
1919import Language.PureScript.CoreFn.Expr
20−import Language.PureScript.CoreFn.Literals
20+import Language.PureScript.AST.Literals
2121import Language.PureScript.CoreFn.Meta
2222import Language.PureScript.CoreFn.Module
2323import Language.PureScript.Environment
@@ -88,18 +88,8 @@ moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
8888 -- Desugars expressions from AST to CoreFn representation.
8989 --
9090 exprToCoreFn :: Maybe SourceSpan -> [Comment] -> Maybe Type -> A.Expr -> Expr Ann
91− exprToCoreFn ss com ty (A.NumericLiteral v) =
92− Literal (ss, com, ty, Nothing) (NumericLiteral v)
93− exprToCoreFn ss com ty (A.StringLiteral v) =
94− Literal (ss, com, ty, Nothing) (StringLiteral v)
95− exprToCoreFn ss com ty (A.CharLiteral v) =
96− Literal (ss, com, ty, Nothing) (CharLiteral v)
97− exprToCoreFn ss com ty (A.BooleanLiteral v) =
98− Literal (ss, com, ty, Nothing) (BooleanLiteral v)
99− exprToCoreFn ss com ty (A.ArrayLiteral vs) =
100− Literal (ss, com, ty, Nothing) (ArrayLiteral $ map (exprToCoreFn ss [] Nothing) vs)
101− exprToCoreFn ss com ty (A.ObjectLiteral vs) =
102− Literal (ss, com, ty, Nothing) (ObjectLiteral $ map (second (exprToCoreFn ss [] Nothing)) vs)
91+ exprToCoreFn ss com ty (A.Literal lit) =
92+ Literal (ss, com, ty, Nothing) (fmap (exprToCoreFn ss com Nothing) lit)
10393 exprToCoreFn ss com ty (A.Accessor name v) =
10494 Accessor (ss, com, ty, Nothing) name (exprToCoreFn ss [] Nothing v)
10595 exprToCoreFn ss com ty (A.ObjectUpdate obj vs) =
@@ -126,7 +116,7 @@ moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
126116 exprToCoreFn ss com (Just ty) v
127117 exprToCoreFn ss com ty (A.Let ds v) =
128118 Let (ss, com, ty, Nothing) (concatMap (declToCoreFn ss []) ds) (exprToCoreFn ss [] Nothing v)
129− exprToCoreFn ss com _ (A.TypeClassDictionaryConstructorApp name (A.TypedValue _ (A.ObjectLiteral vs) _)) =
119+ exprToCoreFn ss com _ (A.TypeClassDictionaryConstructorApp name (A.TypedValue _ (A.Literal (A.ObjectLiteral vs)) _)) =
130120 let args = map (exprToCoreFn ss [] Nothing . snd) $ sortBy (compare `on` fst) vs
131121 ctor = Var (ss, [], Nothing, Just IsTypeClassConstructor) (fmap properToIdent name)
132122 in foldl (App (ss, com, Nothing, Nothing)) ctor args
@@ -152,25 +142,15 @@ moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
152142 -- Desugars case binders from AST to CoreFn representation.
153143 --
154144 binderToCoreFn :: Maybe SourceSpan -> [Comment] -> A.Binder -> Binder Ann
145+ binderToCoreFn ss com (A.LiteralBinder lit) =
146+ LiteralBinder (ss, com, Nothing, Nothing) (fmap (binderToCoreFn ss com) lit)
155147 binderToCoreFn ss com (A.NullBinder) =
156148 NullBinder (ss, com, Nothing, Nothing)
157− binderToCoreFn ss com (A.BooleanBinder b) =
158− LiteralBinder (ss, com, Nothing, Nothing) (BooleanLiteral b)
159− binderToCoreFn ss com (A.StringBinder s) =
160− LiteralBinder (ss, com, Nothing, Nothing) (StringLiteral s)
161− binderToCoreFn ss com (A.CharBinder c) =
162− LiteralBinder (ss, com, Nothing, Nothing) (CharLiteral c)
163− binderToCoreFn ss com (A.NumberBinder n) =
164− LiteralBinder (ss, com, Nothing, Nothing) (NumericLiteral n)
165149 binderToCoreFn ss com (A.VarBinder name) =
166150 VarBinder (ss, com, Nothing, Nothing) name
167151 binderToCoreFn ss com (A.ConstructorBinder dctor@(Qualified mn' _) bs) =
168152 let (_, tctor, _, _) = lookupConstructor env dctor
169153 in ConstructorBinder (ss, com, Nothing, Just $ getConstructorMeta dctor) (Qualified mn' tctor) dctor (map (binderToCoreFn ss []) bs)
170− binderToCoreFn ss com (A.ObjectBinder bs) =
171− LiteralBinder (ss, com, Nothing, Nothing) (ObjectLiteral $ map (second (binderToCoreFn ss [])) bs)
172− binderToCoreFn ss com (A.ArrayBinder bs) =
173− LiteralBinder (ss, com, Nothing, Nothing) (ArrayLiteral $ map (binderToCoreFn ss []) bs)
174154 binderToCoreFn ss com (A.NamedBinder name b) =
175155 NamedBinder (ss, com, Nothing, Nothing) name (binderToCoreFn ss [] b)
176156 binderToCoreFn _ com (A.PositionedBinder ss com1 b) =
src/Language/PureScript/CoreFn/Expr.hs+1−1
@@ -8,7 +8,7 @@ module Language.PureScript.CoreFn.Expr where
88import Control.Arrow ((***))
99
1010import Language.PureScript.CoreFn.Binders
11−import Language.PureScript.CoreFn.Literals
11+import Language.PureScript.AST.Literals
1212import Language.PureScript.Names
1313
1414-- |
src/Language/PureScript/CoreFn/Traversals.hs+3−14
@@ -1,24 +1,13 @@
1−-----------------------------------------------------------------------------
1+-- |
2+-- CoreFn traversal helpers
23--
3−-- Module : Language.PureScript.CoreFn.Traversals
4−-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>, Gary Burgess <gary.burgess@gmail.com>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- | CoreFn traversal helpers
12−--
13−-----------------------------------------------------------------------------
14−
154module Language.PureScript.CoreFn.Traversals where
165
176import Control.Arrow (second, (***), (+++))
187
198import Language.PureScript.CoreFn.Binders
209import Language.PureScript.CoreFn.Expr
21−import Language.PureScript.CoreFn.Literals
10+import Language.PureScript.AST.Literals
2211
2312everywhereOnValues :: (Bind a -> Bind a) ->
2413 (Expr a -> Expr a) ->
src/Language/PureScript/Docs/AsMarkdown.hs+1−2
@@ -29,8 +29,7 @@ import qualified Language.PureScript.Docs.Render as Render
2929-- Markdown-formatted String.
3030--
3131renderModulesAsMarkdown ::
32− (Functor m, Applicative m,
33− MonadError P.MultipleErrors m) =>
32+ (MonadError P.MultipleErrors m) =>
3433 [P.Module] ->
3534 m String
3635renderModulesAsMarkdown =
src/Language/PureScript/Docs/Convert.hs+6−6
@@ -38,7 +38,7 @@ import Language.PureScript.Docs.Convert.ReExports (updateReExports)
3838-- documentation.
3939--
4040convertModulesInPackage ::
41− (Functor m, Applicative m, MonadError P.MultipleErrors m) =>
41+ (MonadError P.MultipleErrors m) =>
4242 [InPackage P.Module] ->
4343 m [Module]
4444convertModulesInPackage modules =
@@ -66,7 +66,7 @@ convertModulesInPackage modules =
6666-- types.
6767--
6868convertModules ::
69− (Functor m, Applicative m, MonadError P.MultipleErrors m) =>
69+ (MonadError P.MultipleErrors m) =>
7070 [P.Module] ->
7171 m [Module]
7272convertModules =
@@ -81,7 +81,7 @@ importPrim = P.addDefaultImport (P.ModuleName [P.ProperName C.prim])
8181-- Convert a sorted list of modules.
8282--
8383convertSorted ::
84− (Functor m, Applicative m, MonadError P.MultipleErrors m) =>
84+ (MonadError P.MultipleErrors m) =>
8585 [P.Module] ->
8686 m [Module]
8787convertSorted modules = do
@@ -99,7 +99,7 @@ convertSorted modules = do
9999-- types.
100100--
101101typeCheckIfNecessary ::
102− (Functor m, Applicative m, MonadError P.MultipleErrors m) =>
102+ (MonadError P.MultipleErrors m) =>
103103 [P.Module] ->
104104 [Module] ->
105105 m [Module]
@@ -122,7 +122,7 @@ typeCheckIfNecessary modules convertedModules =
122122-- were not provided.
123123--
124124typeCheck ::
125− (Functor m, MonadError P.MultipleErrors m) =>
125+ (MonadError P.MultipleErrors m) =>
126126 [P.Module] ->
127127 m ([P.Module], P.Environment)
128128typeCheck =
@@ -182,7 +182,7 @@ runParser p s = either (Left . show) Right $ do
182182-- documentation information from.
183183--
184184partiallyDesugar ::
185− (Functor m, Applicative m, MonadError P.MultipleErrors m) =>
185+ (MonadError P.MultipleErrors m) =>
186186 [P.Module]
187187 -> m (P.Env, [P.Module])
188188partiallyDesugar = P.evalSupplyT 0 . desugar'
src/Language/PureScript/Docs/Convert/ReExports.hs+13−22
@@ -69,8 +69,7 @@ updateReExports env order modules =
6969-- have already been converted.
7070--
7171getReExports ::
72− (Functor m, Applicative m,
73− MonadState (Map P.ModuleName Module) m) =>
72+ (MonadState (Map P.ModuleName Module) m) =>
7473 P.Env ->
7574 P.ModuleName ->
7675 m [(P.ModuleName, [Declaration])]
@@ -105,9 +104,7 @@ getReExports env mn =
105104-- class members are listed.
106105--
107106collectDeclarations ::
108− (Functor m, Applicative m,
109− MonadState (Map P.ModuleName Module) m,
110− MonadReader P.ModuleName m) =>
107+ (MonadState (Map P.ModuleName Module) m, MonadReader P.ModuleName m) =>
111108 P.Imports ->
112109 P.Exports ->
113110 m [(P.ModuleName, [Declaration])]
@@ -154,7 +151,7 @@ collectDeclarations imports exports = do
154151-- instantiate @name@ as both 'P.Ident' and 'P.ProperName'.
155152--
156153findImport ::
157− (Show name, Eq name, Applicative m, MonadReader P.ModuleName m) =>
154+ (Show name, Eq name, MonadReader P.ModuleName m) =>
158155 [P.ImportRecord name] ->
159156 (name, P.ModuleName) ->
160157 m (P.ModuleName, name)
@@ -174,9 +171,8 @@ findImport imps (name, orig) =
174171 internalErrorInModule ("findImport: not found: " ++ show (name, orig))
175172
176173lookupValueDeclaration ::
177− (Applicative m,
178− MonadState (Map P.ModuleName Module) m,
179− MonadReader P.ModuleName m) =>
174+ (MonadState (Map P.ModuleName Module) m,
175+ MonadReader P.ModuleName m) =>
180176 P.ModuleName ->
181177 P.Ident ->
182178 m (P.ModuleName, [Either (String, P.Constraint, ChildDeclaration) Declaration])
@@ -233,9 +229,8 @@ lookupValueDeclaration importedFrom ident = do
233229-- are only included in the output if they are listed in the arguments.
234230--
235231lookupTypeDeclaration ::
236− (Applicative m,
237− MonadState (Map P.ModuleName Module) m,
238− MonadReader P.ModuleName m) =>
232+ (MonadState (Map P.ModuleName Module) m,
233+ MonadReader P.ModuleName m) =>
239234 P.ModuleName ->
240235 P.ProperName 'P.TypeName ->
241236 m (P.ModuleName, [Declaration])
@@ -251,9 +246,8 @@ lookupTypeDeclaration importedFrom ty = do
251246 ("lookupTypeDeclaration: unexpected result: " ++ show other)
252247
253248lookupTypeClassDeclaration ::
254− (Applicative m,
255− MonadState (Map P.ModuleName Module) m,
256− MonadReader P.ModuleName m) =>
249+ (MonadState (Map P.ModuleName Module) m,
250+ MonadReader P.ModuleName m) =>
257251 P.ModuleName ->
258252 P.ProperName 'P.ClassName ->
259253 m (P.ModuleName, [Declaration])
@@ -276,9 +270,8 @@ lookupTypeClassDeclaration importedFrom tyClass = do
276270-- state, or raise an internal error if it is not there.
277271--
278272lookupModuleDeclarations ::
279− (Applicative m,
280− MonadState (Map P.ModuleName Module) m,
281− MonadReader P.ModuleName m) =>
273+ (MonadState (Map P.ModuleName Module) m,
274+ MonadReader P.ModuleName m) =>
282275 String ->
283276 P.ModuleName ->
284277 m [Declaration]
@@ -293,8 +286,7 @@ lookupModuleDeclarations definedIn moduleName = do
293286 pure (allDeclarations mdl)
294287
295288handleTypeClassMembers ::
296− (Functor m, Applicative m,
297− MonadReader P.ModuleName m) =>
289+ (MonadReader P.ModuleName m) =>
298290 Map P.ModuleName [Either (String, P.Constraint, ChildDeclaration) Declaration] ->
299291 Map P.ModuleName [Declaration] ->
300292 m (Map P.ModuleName [Declaration], Map P.ModuleName [Declaration])
@@ -364,8 +356,7 @@ instance Monoid TypeClassEnv where
364356-- Returns a tuple of (values, type classes).
365357--
366358handleEnv ::
367− (Functor m, Applicative m,
368− MonadReader P.ModuleName m) =>
359+ (MonadReader P.ModuleName m) =>
369360 TypeClassEnv ->
370361 m ([Declaration], [Declaration])
371362handleEnv TypeClassEnv{..} =
src/Language/PureScript/Docs/ParseAndBookmark.hs+2−2
@@ -35,7 +35,7 @@ import Language.PureScript.Docs.Convert (collectBookmarks)
3535-- * Collect a list of bookmarks from the whole set of source files
3636-- * Return the parsed modules and the bookmarks
3737parseAndBookmark ::
38− (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadIO m) =>
38+ (MonadError P.MultipleErrors m, MonadIO m) =>
3939 [FilePath]
4040 -> [(PackageName, FilePath)]
4141 -> m ([InPackage P.Module], [Bookmark])
@@ -82,7 +82,7 @@ fileInfoToString (FromDep _ fn) = fn
8282parseFile :: FilePath -> IO (FilePath, String)
8383parseFile input' = (,) input' <$> readFile input'
8484
85−parseAs :: (Functor m, MonadIO m) => (FilePath -> a) -> FilePath -> m (a, String)
85+parseAs :: (MonadIO m) => (FilePath -> a) -> FilePath -> m (a, String)
8686parseAs g = fmap (first g) . liftIO . parseFile
8787
8888getDepsModuleNames :: [InPackage (FilePath, P.Module)] -> M.Map P.ModuleName PackageName
src/Language/PureScript/Errors.hs+23−16
@@ -148,6 +148,7 @@ data SimpleErrorMessage
148148 | CaseBinderLengthDiffers Int [Binder]
149149 | IncorrectAnonymousArgument
150150 | InvalidOperatorInBinder Ident Ident
151+ | DeprecatedRequirePath
151152 deriving (Show)
152153
153154-- | Error message hints, providing more detailed information about failure.
@@ -328,6 +329,7 @@ errorCode em = case unwrapErrorMessage em of
328329 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
329330 IncorrectAnonymousArgument -> "IncorrectAnonymousArgument"
330331 InvalidOperatorInBinder{} -> "InvalidOperatorInBinder"
332+ DeprecatedRequirePath{} -> "DeprecatedRequirePath"
331333
332334-- |
333335-- A stack trace for an error
@@ -447,6 +449,7 @@ errorSuggestion err = case err of
447449 UnusedExplicitImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
448450 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
449451 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
452+ HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
450453 _ -> Nothing
451454
452455 where
@@ -955,9 +958,9 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
955958 , indent $ line $ showSuggestion msg
956959 ]
957960
958− renderSimpleErrorMessage (HidingImport mn refs) =
961+ renderSimpleErrorMessage msg@(HidingImport mn _) =
959962 paras [ line $ "Module " ++ runModuleName mn ++ " has unspecified imports, consider using the inclusive form: "
960− , indent $ line $ "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (map prettyPrintRef refs) ++ ")"
963+ , indent $ line $ showSuggestion msg
961964 ]
962965
963966 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
@@ -974,6 +977,9 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
974977 , line "Only aliases for data constructors may be used in patterns."
975978 ]
976979
980+ renderSimpleErrorMessage DeprecatedRequirePath =
981+ line "The require-path option is deprecated and will be removed in PureScript 0.9."
982+
977983 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
978984 renderHint (ErrorUnifyingTypes t1 t2) detail =
979985 paras [ detail
@@ -1181,31 +1187,32 @@ prettyPrintRef (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
11811187-- Pretty print multiple errors
11821188--
11831189prettyPrintMultipleErrors :: Bool -> MultipleErrors -> String
1184−prettyPrintMultipleErrors full = renderBox . prettyPrintMultipleErrorsBox full
1190+prettyPrintMultipleErrors full = unlines . map renderBox . prettyPrintMultipleErrorsBox full
11851191
11861192-- |
11871193-- Pretty print multiple warnings
11881194--
1189−prettyPrintMultipleWarnings :: Bool -> MultipleErrors -> String
1190−prettyPrintMultipleWarnings full = renderBox . prettyPrintMultipleWarningsBox full
1195+prettyPrintMultipleWarnings :: Bool -> MultipleErrors -> String
1196+prettyPrintMultipleWarnings full = unlines . map renderBox . prettyPrintMultipleWarningsBox full
11911197
11921198-- | Pretty print warnings as a Box
1193−prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> Box.Box
1199+prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> [Box.Box]
11941200prettyPrintMultipleWarningsBox full = prettyPrintMultipleErrorsWith Warning "Warning found:" "Warning" full
11951201
11961202-- | Pretty print errors as a Box
1197−prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
1203+prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> [Box.Box]
11981204prettyPrintMultipleErrorsBox full = prettyPrintMultipleErrorsWith Error "Error found:" "Error" full
11991205
1200−prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> Box.Box
1206+prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> [Box.Box]
12011207prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) =
12021208 let result = prettyPrintSingleError full level True e
1203− in Box.vcat Box.left [ Box.text intro
1204− , result
1205− ]
1209+ in [ Box.vcat Box.left [ Box.text intro
1210+ , result
1211+ ]
1212+ ]
12061213prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) =
12071214 let result = map (prettyPrintSingleError full level True) es
1208− in Box.vsep 1 Box.left $ concat $ zipWith withIntro [1 :: Int ..] result
1215+ in concat $ zipWith withIntro [1 :: Int ..] result
12091216 where
12101217 withIntro i err = [ Box.text (intro ++ " " ++ show i ++ " of " ++ show (length es) ++ ":")
12111218 , Box.moveRight 2 err
@@ -1283,7 +1290,7 @@ renderBox = unlines
12831290rethrow :: (MonadError e m) => (e -> e) -> m a -> m a
12841291rethrow f = flip catchError $ \e -> throwError (f e)
12851292
1286−reifyErrors :: (Functor m, MonadError e m) => m a -> m (Either e a)
1293+reifyErrors :: (MonadError e m) => m a -> m (Either e a)
12871294reifyErrors ma = catchError (fmap Right ma) (return . Left)
12881295
12891296reflectErrors :: (MonadError e m) => m (Either e a) -> m a
@@ -1310,13 +1317,13 @@ withPosition pos (ErrorMessage hints se) = ErrorMessage (PositionedError pos : h
13101317-- |
13111318-- Collect errors in in parallel
13121319--
1313−parU :: (MonadError MultipleErrors m, Functor m) => [a] -> (a -> m b) -> m [b]
1320+parU :: (MonadError MultipleErrors m) => [a] -> (a -> m b) -> m [b]
13141321parU xs f = forM xs (withError . f) >>= collectErrors
13151322 where
1316− withError :: (MonadError MultipleErrors m, Functor m) => m a -> m (Either MultipleErrors a)
1323+ withError :: (MonadError MultipleErrors m) => m a -> m (Either MultipleErrors a)
13171324 withError u = catchError (Right <$> u) (return . Left)
13181325
1319− collectErrors :: (MonadError MultipleErrors m, Functor m) => [Either MultipleErrors a] -> m [a]
1326+ collectErrors :: (MonadError MultipleErrors m) => [Either MultipleErrors a] -> m [a]
13201327 collectErrors es = case lefts es of
13211328 [] -> return $ rights es
13221329 errs -> throwError $ fold errs
src/Language/PureScript/Ide.hs+3−3
@@ -74,12 +74,12 @@ findType :: (PscIde m, MonadLogger m) =>
7474findType search filters =
7575 CompletionResult . getExactMatches search filters <$> getAllModulesWithReexports
7676
77−findPursuitCompletions :: (Applicative m, MonadIO m, MonadLogger m) =>
77+findPursuitCompletions :: (MonadIO m, MonadLogger m) =>
7878 PursuitQuery -> m Success
7979findPursuitCompletions (PursuitQuery q) =
8080 PursuitResult <$> liftIO (searchPursuitForDeclarations q)
8181
82−findPursuitPackages :: (Applicative m, MonadIO m, MonadLogger m) =>
82+findPursuitPackages :: (MonadIO m, MonadLogger m) =>
8383 PursuitQuery -> m Success
8484findPursuitPackages (PursuitQuery q) =
8585 PursuitResult <$> liftIO (findPackagesForModuleIdent q)
@@ -118,7 +118,7 @@ caseSplit l b e csa t = do
118118addClause :: Text -> CS.WildcardAnnotations -> Success
119119addClause t wca = MultilineTextResult (CS.addClause t wca)
120120
121−importsForFile :: (Applicative m, MonadIO m, MonadLogger m, MonadError PscIdeError m) =>
121+importsForFile :: (MonadIO m, MonadLogger m, MonadError PscIdeError m) =>
122122 FilePath -> m Success
123123importsForFile fp = do
124124 imports <- getImportsForFile fp
src/Language/PureScript/Ide/CaseSplit.hs+1−10
@@ -60,15 +60,6 @@ caseSplit q = do
6060 let appliedCtors = map (\(n, ts) -> (n, map applyTypeVars ts)) ctors
6161 pure appliedCtors
6262
63−{- ["EDType {
64− edTypeName = ProperName {runProperName = \"Either\"}
65− , edTypeKind = FunKind Star (FunKind Star Star)
66− , edTypeDeclarationKind =
67− DataType [(\"a\",Just Star),(\"b\",Just Star)]
68− [(ProperName {runProperName = \"Left\"},[TypeVar \"a\"])
69− ,(ProperName {runProperName = \"Right\"},[TypeVar \"b\"])]}"]
70−-}
71−
7263findTypeDeclaration :: (PscIde m, MonadLogger m, MonadError PscIdeError m) =>
7364 ProperName 'TypeName -> m ExternsDeclaration
7465findTypeDeclaration q = do
@@ -87,7 +78,7 @@ findTypeDeclaration' t ExternsFile{..} =
8778 EDType tn _ _ -> tn == t
8879 _ -> False) efDeclarations
8980
90−splitTypeConstructor :: (Applicative m, MonadError PscIdeError m) =>
81+splitTypeConstructor :: (MonadError PscIdeError m) =>
9182 Type -> m (ProperName 'TypeName, [Type])
9283splitTypeConstructor = go []
9384 where
src/Language/PureScript/Ide/Completion.hs+4−4
@@ -24,12 +24,12 @@ getExactMatches search filters modules =
2424
2525completionsFromModules :: [Module] -> [Completion]
2626completionsFromModules = foldMap completionFromModule
27− where
28− completionFromModule :: Module -> [Completion]
29− completionFromModule (moduleIdent, decls) = mapMaybe (completionFromDecl moduleIdent) decls
27+ where
28+ completionFromModule :: Module -> [Completion]
29+ completionFromModule (moduleIdent, decls) = mapMaybe (completionFromDecl moduleIdent) decls
3030
3131completionFromDecl :: ModuleIdent -> ExternDecl -> Maybe Completion
3232completionFromDecl mi (FunctionDecl name type') = Just (Completion (mi, name, type'))
3333completionFromDecl mi (DataDecl name kind) = Just (Completion (mi, name, kind))
34−completionFromDecl _ (ModuleDecl name _) = Just (Completion ("module", name, "module"))
34+completionFromDecl _ (ModuleDecl name _) = Just (Completion ("module", name, "module"))
3535completionFromDecl _ _ = Nothing
src/Language/PureScript/Ide/Error.hs+11−12
@@ -21,21 +21,20 @@ data PscIdeError
2121
2222instance ToJSON PscIdeError where
2323 toJSON err = object
24− [
25− "resultType" .= ("error" :: Text),
26− "result" .= textError err
27− ]
24+ [ "resultType" .= ("error" :: Text)
25+ , "result" .= textError err
26+ ]
2827
2928textError :: PscIdeError -> Text
30−textError (GeneralError msg) = pack msg
31−textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
32−textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
33−textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
34−textError (ParseError parseError msg) = pack $ msg <> ": " <> show (escape parseError)
35− where
29+textError (GeneralError msg) = pack msg
30+textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
31+textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
32+textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
33+textError (ParseError parseError msg) = pack $ msg <> ": " <> show (escape parseError)
34+ where
3635 -- escape newlines and other special chars so we can send the error over the socket as a single line
37− escape :: P.ParseError -> String
38− escape = show
36+ escape :: P.ParseError -> String
37+ escape = show
3938
4039-- | Specialized version of `first` from `Data.Bifunctors`
4140first :: (a -> b) -> Either a r -> Either b r
src/Language/PureScript/Ide/Externs.hs+1−1
@@ -34,7 +34,7 @@ import Language.PureScript.Ide.Types
3434import qualified Language.PureScript.Names as N
3535import qualified Language.PureScript.Pretty as PP
3636
37−readExternFile :: (Applicative m, MonadIO m, MonadError PscIdeError m) =>
37+readExternFile :: (MonadIO m, MonadError PscIdeError m) =>
3838 FilePath -> m PE.ExternsFile
3939readExternFile fp = do
4040 parseResult <- liftIO (decodeT <$> T.readFile fp)
src/Language/PureScript/Ide/Matcher.hs+6−6
@@ -76,8 +76,8 @@ flexMatch pattern = mapMaybe (flexRate pattern)
7676
7777flexRate :: Text -> Completion -> Maybe ScoredCompletion
7878flexRate pattern c@(Completion (_,ident,_)) = do
79− score <- flexScore pattern ident
80− return (c, score)
79+ score <- flexScore pattern ident
80+ return (c, score)
8181
8282-- FlexMatching ala Sublime.
8383-- Borrowed from: http://cdewaka.com/2013/06/fuzzy-pattern-matching-in-haskell/
@@ -88,13 +88,13 @@ flexRate pattern c@(Completion (_,ident,_)) = do
8888flexScore :: Text -> DeclIdent -> Maybe Double
8989flexScore "" _ = Nothing
9090flexScore pat str =
91− case TE.encodeUtf8 str =~ TE.encodeUtf8 pat' :: (Int, Int) of
92− (-1,0) -> Nothing
93− (start,len) -> Just $ calcScore start (start + len)
91+ case TE.encodeUtf8 str =~ TE.encodeUtf8 pat' :: (Int, Int) of
92+ (-1,0) -> Nothing
93+ (start,len) -> Just $ calcScore start (start + len)
9494 where
9595 Just (first,pattern) = T.uncons pat
9696 -- This just interleaves the search string with .*
9797 -- abcd -> a.*b.*c.*d
9898 pat' = first `T.cons` T.concatMap (T.snoc ".*") pattern
9999 calcScore start end =
100− 100.0 / fromIntegral ((1 + start) * (end - start + 1))
100+ 100.0 / fromIntegral ((1 + start) * (end - start + 1))
src/Language/PureScript/Ide/Pursuit.hs+11−11
@@ -10,9 +10,9 @@ import qualified Control.Exception as E
1010import Data.Aeson
1111import Data.ByteString (ByteString)
1212import Data.ByteString.Lazy (fromStrict)
13−import Data.Foldable (toList)
13+import Data.Foldable (toList)
14+import Data.Maybe (mapMaybe)
1415import Data.Monoid ((<>))
15−import Data.Maybe (mapMaybe)
1616import Data.String
1717import Data.Text (Text)
1818import qualified Data.Text as T
@@ -33,12 +33,12 @@ queryPursuit q = do
3333 }
3434 m <- newManager tlsManagerSettings
3535 withHTTP req m $ \resp ->
36− P.fold (\x a -> x <> a) "" id $ responseBody resp
36+ P.fold (<>) "" id $ responseBody resp
3737
3838
3939handler :: HttpException -> IO [a]
40−handler StatusCodeException{} = return []
41−handler _ = return []
40+handler StatusCodeException{} = pure []
41+handler _ = pure []
4242
4343searchPursuitForDeclarations :: Text -> IO [PursuitResponse]
4444searchPursuitForDeclarations query =
@@ -54,12 +54,12 @@ searchPursuitForDeclarations query =
5454
5555findPackagesForModuleIdent :: Text -> IO [PursuitResponse]
5656findPackagesForModuleIdent query =
57− (do r <- queryPursuit query
58− let results' = decode (fromStrict r) :: Maybe Array
59− case results' of
60− Nothing -> pure []
61− Just results -> pure (mapMaybe isModuleResponse (map fromJSON (toList results)))) `E.catch`
62− handler
57+ (do r <- queryPursuit query
58+ let results' = decode (fromStrict r) :: Maybe Array
59+ case results' of
60+ Nothing -> pure []
61+ Just results -> pure (mapMaybe isModuleResponse (map fromJSON (toList results)))) `E.catch`
62+ handler
6363 where
6464 isModuleResponse (Success a@ModuleResponse{}) = Just a
6565 isModuleResponse _ = Nothing
src/Language/PureScript/Ide/Reexports.hs+21−19
@@ -15,10 +15,10 @@ import Language.PureScript.Ide.Types
1515
1616getReexports :: Module -> [ExternDecl]
1717getReexports (mn, decls)= concatMap getExport decls
18− where getExport d
19− | (Export mn') <- d
20− , mn /= mn' = replaceExportWithAliases decls mn'
21− | otherwise = []
18+ where getExport d
19+ | (Export mn') <- d
20+ , mn /= mn' = replaceExportWithAliases decls mn'
21+ | otherwise = []
2222
2323dependencyToExport :: ExternDecl -> ExternDecl
2424dependencyToExport (Dependency m _ _) = Export m
@@ -51,23 +51,25 @@ removeExportDecls = fmap (filter (not . isExport))
5151
5252replaceReexports :: Module -> Map ModuleIdent [ExternDecl] -> Module
5353replaceReexports m db = result
54− where reexports = getReexports m
55− result = foldl go (removeExportDecls m) reexports
54+ where
55+ reexports = getReexports m
56+ result = foldl go (removeExportDecls m) reexports
5657
57− go :: Module -> ExternDecl -> Module
58− go m' re@(Export name) = replaceReexport re m' (getModule name)
59− go _ _ = error "partiality! woohoo"
58+ go :: Module -> ExternDecl -> Module
59+ go m' re@(Export name) = replaceReexport re m' (getModule name)
60+ go _ _ = error "partiality! woohoo"
6061
61− getModule :: ModuleIdent -> Module
62− getModule name = clean res
63− where res = fromMaybe emptyModule $ (name , ) <$> Map.lookup name db
64− -- we have to do this because keeping self exports in will result in
65− -- infinite loops
66− clean (mn, decls) = (mn,) (filter (/= Export mn) decls)
62+ getModule :: ModuleIdent -> Module
63+ getModule name = clean res
64+ where
65+ res = fromMaybe emptyModule $ (name , ) <$> Map.lookup name db
66+ -- we have to do this because keeping self exports in will result in
67+ -- infinite loops
68+ clean (mn, decls) = (mn,) (filter (/= Export mn) decls)
6769
6870resolveReexports :: Map ModuleIdent [ExternDecl] -> Module -> Module
69−resolveReexports modules m = do
71+resolveReexports modules m =
7072 let replaced = replaceReexports m modules
71− if null . getReexports $ replaced
72− then replaced
73− else resolveReexports modules replaced
73+ in if null (getReexports replaced)
74+ then replaced
75+ else resolveReexports modules replaced
src/Language/PureScript/Ide/SourceFile.hs+40−40
@@ -3,8 +3,7 @@
33{-# LANGUAGE OverloadedStrings #-}
44module Language.PureScript.Ide.SourceFile where
55
6−import Prelude ()
7−import Prelude.Compat
6+import Prelude
87
98import Control.Monad.Error.Class
109import Control.Monad.IO.Class
@@ -22,7 +21,7 @@ import qualified Language.PureScript.Names as N
2221import qualified Language.PureScript.Parser as P
2322import System.Directory
2423
25−parseModuleFromFile :: (Applicative m, MonadIO m, MonadError PscIdeError m) =>
24+parseModuleFromFile :: (MonadIO m, MonadError PscIdeError m) =>
2625 FilePath -> m D.Module
2726parseModuleFromFile fp = do
2827 exists <- liftIO (doesFileExist fp)
@@ -46,24 +45,25 @@ getImports (D.Module _ _ _ declarations _) =
4645 isImport (D.PositionedDeclaration _ _ (i@D.ImportDeclaration{})) = Just i
4746 isImport _ = Nothing
4847
49−getImportsForFile :: (Applicative m, MonadIO m, MonadError PscIdeError m) =>
48+getImportsForFile :: (MonadIO m, MonadError PscIdeError m) =>
5049 FilePath -> m [ModuleImport]
5150getImportsForFile fp = do
5251 module' <- parseModuleFromFile fp
5352 let imports = getImports module'
5453 pure (mkModuleImport . unwrapPositionedImport <$> imports)
55− where mkModuleImport (D.ImportDeclaration mn importType' qualifier _) =
56− ModuleImport
57− (T.pack (N.runModuleName mn))
58− importType'
59− (T.pack . N.runModuleName <$> qualifier)
60− mkModuleImport _ = error "Shouldn't have gotten anything but Imports here"
61− unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier b) =
62− D.ImportDeclaration mn (unwrapImportType importType') qualifier b
63− unwrapPositionedImport x = x
64− unwrapImportType (D.Explicit decls) = D.Explicit (map unwrapPositionedRef decls)
65− unwrapImportType (D.Hiding decls) = D.Hiding (map unwrapPositionedRef decls)
66− unwrapImportType D.Implicit = D.Implicit
54+ where
55+ mkModuleImport (D.ImportDeclaration mn importType' qualifier _) =
56+ ModuleImport
57+ (T.pack (N.runModuleName mn))
58+ importType'
59+ (T.pack . N.runModuleName <$> qualifier)
60+ mkModuleImport _ = error "Shouldn't have gotten anything but Imports here"
61+ unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier b) =
62+ D.ImportDeclaration mn (unwrapImportType importType') qualifier b
63+ unwrapPositionedImport x = x
64+ unwrapImportType (D.Explicit decls) = D.Explicit (map unwrapPositionedRef decls)
65+ unwrapImportType (D.Hiding decls) = D.Hiding (map unwrapPositionedRef decls)
66+ unwrapImportType D.Implicit = D.Implicit
6767
6868getPositionedImports :: D.Module -> [D.Declaration]
6969getPositionedImports (D.Module _ _ _ declarations _) =
@@ -73,34 +73,34 @@ getPositionedImports (D.Module _ _ _ declarations _) =
7373 isImport _ = Nothing
7474
7575getDeclPosition :: D.Module -> String -> Maybe SP.SourceSpan
76−getDeclPosition m ident =
77− let decls = getDeclarations m
78− in getFirst (foldMap (match ident) decls)
79− where match q (D.PositionedDeclaration ss _ decl) = First (if go q decl
80− then Just ss
81− else Nothing)
82− match _ _ = First Nothing
76+getDeclPosition m ident = getFirst (foldMap (match ident) decls)
77+ where
78+ decls = getDeclarations m
79+ match q (D.PositionedDeclaration ss _ decl) = First (if go q decl
80+ then Just ss
81+ else Nothing)
82+ match _ _ = First Nothing
8383
84− go q (D.DataDeclaration _ name _ constructors) =
85− properEqual name q || any (\(x,_) -> properEqual x q) constructors
86− go q (D.DataBindingGroupDeclaration decls) = any (go q) decls
87− go q (D.TypeSynonymDeclaration name _ _) = properEqual name q
88− go q (D.TypeDeclaration ident' _) = identEqual ident' q
89− go q (D.ValueDeclaration ident' _ _ _) = identEqual ident' q
90− go q (D.ExternDeclaration ident' _) = identEqual ident' q
91− go q (D.ExternDataDeclaration name _) = properEqual name q
92− go q (D.TypeClassDeclaration name _ _ members) =
93− properEqual name q || any (go q . unwrapPositioned) members
94− go q (D.TypeInstanceDeclaration ident' _ _ _ _) =
95− identEqual ident' q
96− go _ _ = False
84+ go q (D.DataDeclaration _ name _ constructors) =
85+ properEqual name q || any (\(x,_) -> properEqual x q) constructors
86+ go q (D.DataBindingGroupDeclaration decls') = any (go q) decls'
87+ go q (D.TypeSynonymDeclaration name _ _) = properEqual name q
88+ go q (D.TypeDeclaration ident' _) = identEqual ident' q
89+ go q (D.ValueDeclaration ident' _ _ _) = identEqual ident' q
90+ go q (D.ExternDeclaration ident' _) = identEqual ident' q
91+ go q (D.ExternDataDeclaration name _) = properEqual name q
92+ go q (D.TypeClassDeclaration name _ _ members) =
93+ properEqual name q || any (go q . unwrapPositioned) members
94+ go q (D.TypeInstanceDeclaration ident' _ _ _ _) =
95+ identEqual ident' q
96+ go _ _ = False
9797
98− properEqual x q = N.runProperName x == q
99− identEqual x q = N.runIdent x == q
98+ properEqual x q = N.runProperName x == q
99+ identEqual x q = N.runIdent x == q
100100
101101goToDefinition :: String -> FilePath -> IO (Maybe SP.SourceSpan)
102102goToDefinition q fp = do
103103 m <- runExceptT (parseModuleFromFile fp)
104104 case m of
105− Right module' -> return $ getDeclPosition module' q
106− Left _ -> return Nothing
105+ Right module' -> pure (getDeclPosition module' q)
106+ Left _ -> pure Nothing
src/Language/PureScript/Ide/State.hs+10−10
@@ -25,38 +25,38 @@ import Language.PureScript.Ide.Reexports
2525import Language.PureScript.Ide.Types
2626import Language.PureScript.Names
2727
28−getPscIdeState :: (PscIde m, Functor m) =>
28+getPscIdeState :: (PscIde m) =>
2929 m (M.Map ModuleIdent [ExternDecl])
3030getPscIdeState = do
3131 stateVar <- envStateVar <$> ask
3232 liftIO $ pscStateModules <$> readTVarIO stateVar
3333
34−getExternFiles :: (PscIde m, Functor m) =>
34+getExternFiles :: (PscIde m) =>
3535 m (M.Map ModuleName ExternsFile)
3636getExternFiles = do
3737 stateVar <- envStateVar <$> ask
3838 liftIO (externsFiles <$> readTVarIO stateVar)
3939
40−getAllDecls :: (PscIde m, Functor m) => m [ExternDecl]
40+getAllDecls :: (PscIde m) => m [ExternDecl]
4141getAllDecls = concat <$> getPscIdeState
4242
43−getAllModules :: (PscIde m, Functor m) => m [Module]
43+getAllModules :: (PscIde m) => m [Module]
4444getAllModules = M.toList <$> getPscIdeState
4545
46−getAllModulesWithReexports :: (PscIde m, MonadLogger m, Applicative m) =>
46+getAllModulesWithReexports :: (PscIde m, MonadLogger m) =>
4747 m [Module]
4848getAllModulesWithReexports = do
4949 mis <- M.keys <$> getPscIdeState
5050 ms <- traverse getModuleWithReexports mis
5151 pure (catMaybes ms)
5252
53−getModule :: (PscIde m, MonadLogger m, Applicative m) =>
53+getModule :: (PscIde m, MonadLogger m) =>
5454 ModuleIdent -> m (Maybe Module)
5555getModule m = do
5656 modules <- getPscIdeState
5757 pure ((m,) <$> M.lookup m modules)
5858
59−getModuleWithReexports :: (PscIde m, MonadLogger m, Applicative m) =>
59+getModuleWithReexports :: (PscIde m, MonadLogger m) =>
6060 ModuleIdent -> m (Maybe Module)
6161getModuleWithReexports mi = do
6262 m <- getModule mi
@@ -73,8 +73,8 @@ insertModule externsFile = do
7373
7474insertModule' :: TVar PscIdeState -> ExternsFile -> STM ()
7575insertModule' st ef = do
76− modifyTVar (st) $ \x ->
76+ modifyTVar st $ \x ->
7777 x { externsFiles = M.insert (efModuleName ef) ef (externsFiles x)
78− , pscStateModules = let (mn, decls ) = convertExterns ef
79− in M.insert mn decls (pscStateModules x)
78+ , pscStateModules = let (mn, decls) = convertExterns ef
79+ in M.insert mn decls (pscStateModules x)
8080 }
src/Language/PureScript/Ide/Types.hs+76−78
@@ -33,21 +33,26 @@ type Type = Text
3333data Fixity = Infix | Infixl | Infixr deriving(Show, Eq, Ord)
3434
3535data ExternDecl
36− = FunctionDecl { functionName :: DeclIdent
37− , functionType :: Type
38− }
39− | FixityDeclaration Fixity
40− Int
41− DeclIdent
42− | Dependency { dependencyModule :: ModuleIdent
43− , dependencyNames :: [Text]
44− , dependencyAlias :: Maybe Text
45− }
46− | ModuleDecl ModuleIdent
47− [DeclIdent]
48− | DataDecl DeclIdent
49− Text
50− | Export ModuleIdent
36+ -- | A function/value declaration
37+ = FunctionDecl
38+ DeclIdent -- The functions name
39+ Type -- The functions type
40+ | FixityDeclaration Fixity Int DeclIdent
41+ -- | A Dependency onto another Module
42+ | Dependency
43+ ModuleIdent -- name of the dependency
44+ [Text] -- explicit imports
45+ (Maybe Text) -- An eventual qualifier
46+
47+ -- | A module declaration
48+ | ModuleDecl
49+ ModuleIdent -- The modules name
50+ [DeclIdent] -- The exported identifiers
51+ -- | A data/newtype declaration
52+ | DataDecl DeclIdent -- The type name
53+ Text -- The "type"
54+ -- | An exported module
55+ | Export ModuleIdent -- The exported Modules name
5156 deriving (Show,Eq,Ord)
5257
5358instance ToJSON ExternDecl where
@@ -63,22 +68,22 @@ instance ToJSON ExternDecl where
6368type Module = (ModuleIdent, [ExternDecl])
6469
6570data Configuration =
66− Configuration {
67− confOutputPath :: FilePath
71+ Configuration
72+ { confOutputPath :: FilePath
6873 , confDebug :: Bool
6974 }
7075
7176data PscIdeEnvironment =
72− PscIdeEnvironment {
73− envStateVar :: TVar PscIdeState
77+ PscIdeEnvironment
78+ { envStateVar :: TVar PscIdeState
7479 , envConfiguration :: Configuration
7580 }
7681
77−type PscIde m = (Applicative m, MonadIO m, MonadReader PscIdeEnvironment m)
82+type PscIde m = (MonadIO m, MonadReader PscIdeEnvironment m)
7883
7984data PscIdeState =
80− PscIdeState {
81− pscStateModules :: M.Map Text [ExternDecl]
85+ PscIdeState
86+ { pscStateModules :: M.Map Text [ExternDecl]
8287 , externsFiles :: M.Map ModuleName ExternsFile
8388 } deriving Show
8489
@@ -90,29 +95,32 @@ newtype Completion =
9095 deriving (Show,Eq)
9196
9297data ModuleImport =
93− ModuleImport {
94− importModuleName :: ModuleIdent
98+ ModuleImport
99+ { importModuleName :: ModuleIdent
95100 , importType :: D.ImportDeclarationType
96101 , importQualifier :: Maybe Text
97102 } deriving(Show)
98103
99104instance Eq ModuleImport where
100− mi1 == mi2 = importModuleName mi1 == importModuleName mi2
101− && importQualifier mi1 == importQualifier mi2
105+ mi1 == mi2 =
106+ importModuleName mi1 == importModuleName mi2
107+ && importQualifier mi1 == importQualifier mi2
102108
103109instance ToJSON ModuleImport where
104110 toJSON (ModuleImport mn D.Implicit qualifier) =
105− object $ ["module" .= mn
106− , "importType" .= ("implicit" :: Text)
107− ] ++ fmap (\x -> "qualifier" .= x) (maybeToList qualifier)
111+ object $ [ "module" .= mn
112+ , "importType" .= ("implicit" :: Text)
113+ ] ++ fmap (\x -> "qualifier" .= x) (maybeToList qualifier)
108114 toJSON (ModuleImport mn (D.Explicit refs) _) =
109− object ["module" .= mn
115+ object [ "module" .= mn
110116 , "importType" .= ("explicit" :: Text)
111− , "identifiers" .= (identifierFromDeclarationRef <$> refs)]
117+ , "identifiers" .= (identifierFromDeclarationRef <$> refs)
118+ ]
112119 toJSON (ModuleImport mn (D.Hiding refs) _) =
113− object ["module" .= mn
120+ object [ "module" .= mn
114121 , "importType" .= ("hiding" :: Text)
115− , "identifiers" .= (identifierFromDeclarationRef <$> refs)]
122+ , "identifiers" .= (identifierFromDeclarationRef <$> refs)
123+ ]
116124
117125identifierFromDeclarationRef :: D.DeclarationRef -> String
118126identifierFromDeclarationRef (D.TypeRef name _) = N.runProperName name
@@ -121,16 +129,16 @@ identifierFromDeclarationRef (D.TypeClassRef name) = N.runProperName name
121129identifierFromDeclarationRef _ = ""
122130
123131instance FromJSON Completion where
124− parseJSON (Object o) = do
125− m <- o .: "module"
126− d <- o .: "identifier"
127− t <- o .: "type"
128− return $ Completion (m, d, t)
129− parseJSON _ = mzero
132+ parseJSON (Object o) = do
133+ m <- o .: "module"
134+ d <- o .: "identifier"
135+ t <- o .: "type"
136+ pure (Completion (m, d, t))
137+ parseJSON _ = mzero
130138
131139instance ToJSON Completion where
132− toJSON (Completion (m,d,t)) =
133− object ["module" .= m, "identifier" .= d, "type" .= t]
140+ toJSON (Completion (m,d,t)) =
141+ object ["module" .= m, "identifier" .= d, "type" .= t]
134142
135143data Success =
136144 CompletionResult [Completion]
@@ -161,23 +169,22 @@ data PursuitSearchType = Package | Identifier
161169
162170instance FromJSON PursuitSearchType where
163171 parseJSON (String t) = case t of
164− "package" -> return Package
165− "completion" -> return Identifier
172+ "package" -> pure Package
173+ "completion" -> pure Identifier
166174 _ -> mzero
167175 parseJSON _ = mzero
168176
169177instance FromJSON PursuitQuery where
170− parseJSON o = fmap PursuitQuery (parseJSON o)
171−
172−data PursuitResponse
173− = ModuleResponse { moduleResponseName :: Text
174− , moduleResponsePackage :: Text}
175− | DeclarationResponse { declarationResponseType :: Text
176− , declarationResponseModule :: Text
177− , declarationResponseIdent :: Text
178− , declarationResponsePackage :: Text
179− }
180− deriving (Show,Eq)
178+ parseJSON o = PursuitQuery <$> (parseJSON o)
179+
180+data PursuitResponse =
181+ -- | A Pursuit Response for a module. Consists of the modules name and the
182+ -- package it belongs to
183+ ModuleResponse ModuleIdent Text
184+ -- | A Pursuit Response for a declaration. Consist of the declarations type,
185+ -- module, name and package
186+ | DeclarationResponse Type ModuleIdent DeclIdent Text
187+ deriving (Show,Eq)
181188
182189instance FromJSON PursuitResponse where
183190 parseJSON (Object o) = do
@@ -186,22 +193,12 @@ instance FromJSON PursuitResponse where
186193 (type' :: String) <- info .: "type"
187194 case type' of
188195 "module" -> do
189− name <- info .: "module"
190− return
191− ModuleResponse
192− { moduleResponseName = name
193− , moduleResponsePackage = package
194− }
196+ name <- info .: "module"
197+ pure (ModuleResponse name package)
195198 "declaration" -> do
196− moduleName <- info .: "module"
197− Right (ident, declType) <- typeParse <$> o .: "text"
198− return
199− DeclarationResponse
200− { declarationResponseType = declType
201− , declarationResponseModule = moduleName
202− , declarationResponseIdent = ident
203− , declarationResponsePackage = package
204− }
199+ moduleName <- info .: "module"
200+ Right (ident, declType) <- typeParse <$> o .: "text"
201+ pure (DeclarationResponse declType moduleName ident package)
205202 _ -> mzero
206203 parseJSON _ = mzero
207204
@@ -217,7 +214,7 @@ typeParse t = case parse parseType "" t of
217214 _ <- string "::"
218215 spaces
219216 type' <- many1 anyChar
220− return (unpack name, type')
217+ pure (unpack name, type')
221218
222219identifier :: Parser Text
223220identifier = do
@@ -227,14 +224,15 @@ identifier = do
227224 between (char '(') (char ')') (many1 (noneOf ", )")) <|>
228225 many1 (noneOf ", )")
229226 spaces
230− return (pack ident)
227+ pure (pack ident)
231228
232229instance ToJSON PursuitResponse where
233− toJSON ModuleResponse{..} =
234− object ["module" .= moduleResponseName, "package" .= moduleResponsePackage]
235− toJSON DeclarationResponse{..} =
230+ toJSON (ModuleResponse name package) =
231+ object ["module" .= name, "package" .= package]
232+ toJSON (DeclarationResponse module' ident type' package) =
236233 object
237− [ "module" .= declarationResponseModule
238− , "ident" .= declarationResponseIdent
239− , "type" .= declarationResponseType
240− , "package" .= declarationResponsePackage]
234+ [ "module" .= module'
235+ , "ident" .= ident
236+ , "type" .= type'
237+ , "package" .= package
238+ ]
src/Language/PureScript/Kinds.hs+1−1
@@ -42,7 +42,7 @@ everywhereOnKinds f = go
4242 go (FunKind k1 k2) = f (FunKind (go k1) (go k2))
4343 go other = f other
4444
45−everywhereOnKindsM :: (Functor m, Applicative m, Monad m) => (Kind -> m Kind) -> Kind -> m Kind
45+everywhereOnKindsM :: Monad m => (Kind -> m Kind) -> Kind -> m Kind
4646everywhereOnKindsM f = go
4747 where
4848 go (Row k1) = (Row <$> go k1) >>= f
src/Language/PureScript/Linter.hs+1−1
@@ -29,7 +29,7 @@ import Language.PureScript.Linter.Imports as L
2929-- | Lint the PureScript AST.
3030-- |
3131-- | Right now, this pass only performs a shadowing check.
32−lint :: forall m. (Applicative m, MonadWriter MultipleErrors m) => Module -> m ()
32+lint :: forall m. (MonadWriter MultipleErrors m) => Module -> m ()
3333lint (Module _ _ mn ds _) = censor (addHint (ErrorInModule mn)) $ mapM_ lintDeclaration ds
3434 where
3535 moduleNames :: S.Set Ident
src/Language/PureScript/Linter/Exhaustive.hs+17−14
@@ -24,6 +24,7 @@ import Control.Monad.Writer.Class
2424
2525import Language.PureScript.Crash
2626import Language.PureScript.AST.Binders
27+import Language.PureScript.AST.Literals
2728import Language.PureScript.AST.Declarations
2829import Language.PureScript.Environment
2930import Language.PureScript.Names as P
@@ -119,12 +120,12 @@ missingCasesSingle env mn NullBinder cb@(ConstructorBinder con _) =
119120missingCasesSingle env mn cb@(ConstructorBinder con bs) (ConstructorBinder con' bs')
120121 | con == con' = let (bs'', pr) = missingCasesMultiple env mn bs bs' in (map (ConstructorBinder con) bs'', pr)
121122 | otherwise = ([cb], return False)
122−missingCasesSingle env mn NullBinder (ObjectBinder bs) =
123− (map (ObjectBinder . zip (map fst bs)) allMisses, pr)
123+missingCasesSingle env mn NullBinder (LiteralBinder (ObjectLiteral bs)) =
124+ (map (LiteralBinder . ObjectLiteral . zip (map fst bs)) allMisses, pr)
124125 where
125126 (allMisses, pr) = missingCasesMultiple env mn (initialize $ length bs) (map snd bs)
126−missingCasesSingle env mn (ObjectBinder bs) (ObjectBinder bs') =
127− (map (ObjectBinder . zip sortedNames) allMisses, pr)
127+missingCasesSingle env mn (LiteralBinder (ObjectLiteral bs)) (LiteralBinder (ObjectLiteral bs')) =
128+ (map (LiteralBinder . ObjectLiteral . zip sortedNames) allMisses, pr)
128129 where
129130 (allMisses, pr) = uncurry (missingCasesMultiple env mn) (unzip binders)
130131
@@ -141,10 +142,10 @@ missingCasesSingle env mn (ObjectBinder bs) (ObjectBinder bs') =
141142 compBS e s b b' = (s, compB e b b')
142143
143144 (sortedNames, binders) = unzip $ genericMerge (compBS NullBinder) sbs sbs'
144−missingCasesSingle _ _ NullBinder (BooleanBinder b) = ([BooleanBinder $ not b], return True)
145−missingCasesSingle _ _ (BooleanBinder bl) (BooleanBinder br)
145+missingCasesSingle _ _ NullBinder (LiteralBinder (BooleanLiteral b)) = ([LiteralBinder . BooleanLiteral $ not b], return True)
146+missingCasesSingle _ _ (LiteralBinder (BooleanLiteral bl)) (LiteralBinder (BooleanLiteral br))
146147 | bl == br = ([], return True)
147− | otherwise = ([BooleanBinder bl], return False)
148+ | otherwise = ([LiteralBinder $ BooleanLiteral bl], return False)
148149missingCasesSingle env mn b (PositionedBinder _ _ cb) = missingCasesSingle env mn b cb
149150missingCasesSingle env mn b (TypedBinder _ cb) = missingCasesSingle env mn b cb
150151missingCasesSingle _ _ b _ = ([b], Left Unknown)
@@ -201,9 +202,11 @@ isExhaustiveGuard :: Either [(Guard, Expr)] Expr -> Bool
201202isExhaustiveGuard (Left gs) = not . null $ filter (\(g, _) -> isOtherwise g) gs
202203 where
203204 isOtherwise :: Expr -> Bool
204− isOtherwise (TypedValue _ (BooleanLiteral True) _) = True
205− isOtherwise (TypedValue _ (Var (Qualified (Just (ModuleName [ProperName "Prelude"])) (Ident "otherwise"))) _) = True
206− isOtherwise (TypedValue _ (Var (Qualified (Just (ModuleName [ProperName "Data", ProperName "Boolean"])) (Ident "otherwise"))) _) = True
205+ isOtherwise (Literal (BooleanLiteral True)) = True
206+ isOtherwise (Var (Qualified (Just (ModuleName [ProperName "Prelude"])) (Ident "otherwise"))) = True
207+ isOtherwise (Var (Qualified (Just (ModuleName [ProperName "Data", ProperName "Boolean"])) (Ident "otherwise"))) = True
208+ isOtherwise (TypedValue _ e _) = isOtherwise e
209+ isOtherwise (PositionedValue _ _ e) = isOtherwise e
207210 isOtherwise _ = False
208211isExhaustiveGuard (Right _) = True
209212
@@ -258,7 +261,7 @@ checkExhaustive hasConstraint env mn numArgs cas = makeResult . first nub $ fold
258261-- |
259262-- Exhaustivity checking over a list of declarations
260263--
261−checkExhaustiveDecls :: forall m. (Applicative m, MonadWriter MultipleErrors m) => Environment -> ModuleName -> [Declaration] -> m ()
264+checkExhaustiveDecls :: forall m. MonadWriter MultipleErrors m => Environment -> ModuleName -> [Declaration] -> m ()
262265checkExhaustiveDecls env mn = mapM_ onDecl
263266 where
264267 onDecl :: Declaration -> m ()
@@ -272,8 +275,8 @@ checkExhaustiveDecls env mn = mapM_ onDecl
272275
273276 onExpr :: Bool -> Expr -> m ()
274277 onExpr isP (UnaryMinus e) = onExpr isP e
275− onExpr isP (ArrayLiteral es) = mapM_ (onExpr isP) es
276− onExpr isP (ObjectLiteral es) = mapM_ (onExpr isP . snd) es
278+ onExpr isP (Literal (ArrayLiteral es)) = mapM_ (onExpr isP) es
279+ onExpr isP (Literal (ObjectLiteral es)) = mapM_ (onExpr isP . snd) es
277280 onExpr isP (TypeClassDictionaryConstructorApp _ e) = onExpr isP e
278281 onExpr isP (Accessor _ e) = onExpr isP e
279282 onExpr isP (ObjectUpdate o es) = onExpr isP o >> mapM_ (onExpr isP . snd) es
@@ -307,5 +310,5 @@ checkExhaustiveDecls env mn = mapM_ onDecl
307310-- |
308311-- Exhaustivity checking over a single module
309312--
310−checkExhaustiveModule :: forall m. (Applicative m, MonadWriter MultipleErrors m) => Environment -> Module -> m ()
313+checkExhaustiveModule :: forall m. MonadWriter MultipleErrors m => Environment -> Module -> m ()
311314checkExhaustiveModule env (Module _ _ mn ds _) = censor (addHint (ErrorInModule mn)) $ checkExhaustiveDecls env mn ds
src/Language/PureScript/Linter/Imports.hs+9−8
@@ -70,7 +70,7 @@ type UsedImports = M.Map ModuleName [Name]
7070--
7171lintImports
7272 :: forall m
73− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
73+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
7474 => Module
7575 -> Env
7676 -> UsedImports
@@ -79,8 +79,8 @@ lintImports (Module _ _ mn mdecls mexports) env usedImps = do
7979
8080 let scope = maybe nullImports (\(_, imps, _) -> imps) (M.lookup mn env)
8181 usedImps' = foldr (elaborateUsed scope) usedImps exportedModules
82− numImplicitImports = getSum $ foldMap (Sum . countImplicitImports) mdecls
83− allowImplicit = numImplicitImports == 1
82+ numOpenImports = getSum $ foldMap (Sum . countOpenImports) mdecls
83+ allowImplicit = numOpenImports == 1
8484
8585 imps <- M.toAscList <$> findImports mdecls
8686
@@ -106,10 +106,11 @@ lintImports (Module _ _ mn mdecls mexports) env usedImps = do
106106
107107 where
108108
109− countImplicitImports :: Declaration -> Int
110− countImplicitImports (ImportDeclaration mn' Implicit _ _) | not (isPrim mn') = 1
111− countImplicitImports (PositionedDeclaration _ _ d) = countImplicitImports d
112− countImplicitImports _ = 0
109+ countOpenImports :: Declaration -> Int
110+ countOpenImports (ImportDeclaration mn' Implicit Nothing _) | not (isPrim mn') = 1
111+ countOpenImports (ImportDeclaration mn' (Hiding _) Nothing _) | not (isPrim mn') = 1
112+ countOpenImports (PositionedDeclaration _ _ d) = countOpenImports d
113+ countOpenImports _ = 0
113114
114115 -- Checks whether a module is the Prim module - used to suppress any checks
115116 -- made, as Prim is always implicitly imported.
@@ -169,7 +170,7 @@ lintImports (Module _ _ mn mdecls mexports) env usedImps = do
169170
170171lintImportDecl
171172 :: forall m
172− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
173+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
173174 => Env
174175 -> ModuleName
175176 -> Maybe ModuleName
src/Language/PureScript/Make.hs+4−1
@@ -145,11 +145,14 @@ data RebuildPolicy
145145-- If timestamps have not changed, the externs file can be used to provide the module's types without
146146-- having to typecheck the module again.
147147--
148−make :: forall m. (Functor m, Applicative m, Monad m, MonadBaseControl IO m, MonadReader Options m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
148+make :: forall m. (Monad m, MonadBaseControl IO m, MonadReader Options m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
149149 => MakeActions m
150150 -> [Module]
151151 -> m Environment
152152make MakeActions{..} ms = do
153+ requirePath <- asks optionsRequirePath
154+ when (requirePath /= Nothing) $ tell $ errorMessage DeprecatedRequirePath
155+
153156 checkModuleNamesAreUnique
154157
155158 (sorted, graph) <- sortModules ms
src/Language/PureScript/Parser/Declarations.hs+28−37
@@ -260,7 +260,7 @@ parseModule = do
260260 return $ Module ss comments name decls exports
261261
262262-- | Parse a collection of modules in parallel
263−parseModulesFromFiles :: forall m k. (MonadError MultipleErrors m, Functor m) =>
263+parseModulesFromFiles :: forall m k. (MonadError MultipleErrors m) =>
264264 (k -> FilePath) -> [(k, String)] -> m [(k, Module)]
265265parseModulesFromFiles toFilePath input = do
266266 modules <- flip parU id $ map wrapError $ inParallel $ flip map input $ \(k, content) -> do
@@ -299,23 +299,23 @@ parseModules = mark (P.many (same *> parseModule)) <* P.eof
299299booleanLiteral :: TokenParser Bool
300300booleanLiteral = (reserved "true" >> return True) P.<|> (reserved "false" >> return False)
301301
302−parseNumericLiteral :: TokenParser Expr
302+parseNumericLiteral :: TokenParser (Literal a)
303303parseNumericLiteral = NumericLiteral <$> number
304304
305−parseCharLiteral :: TokenParser Expr
305+parseCharLiteral :: TokenParser (Literal a)
306306parseCharLiteral = CharLiteral <$> charLiteral
307307
308−parseStringLiteral :: TokenParser Expr
308+parseStringLiteral :: TokenParser (Literal a)
309309parseStringLiteral = StringLiteral <$> stringLiteral
310310
311−parseBooleanLiteral :: TokenParser Expr
311+parseBooleanLiteral :: TokenParser (Literal a)
312312parseBooleanLiteral = BooleanLiteral <$> booleanLiteral
313313
314−parseArrayLiteral :: TokenParser Expr
315−parseArrayLiteral = ArrayLiteral <$> squares (commaSep parseValue)
314+parseArrayLiteral :: TokenParser a -> TokenParser (Literal a)
315+parseArrayLiteral p = ArrayLiteral <$> squares (commaSep p)
316316
317−parseObjectLiteral :: TokenParser Expr
318−parseObjectLiteral = ObjectLiteral <$> braces (commaSep parseIdentifierAndValue)
317+parseObjectLiteral :: TokenParser (String, a) -> TokenParser (Literal a)
318+parseObjectLiteral p = ObjectLiteral <$> braces (commaSep p)
319319
320320parseIdentifierAndValue :: TokenParser (String, Expr)
321321parseIdentifierAndValue =
@@ -376,12 +376,12 @@ parseLet = do
376376parseValueAtom :: TokenParser Expr
377377parseValueAtom = P.choice
378378 [ parseAnonymousArgument
379− , parseNumericLiteral
380− , parseCharLiteral
381− , parseStringLiteral
382− , parseBooleanLiteral
383− , parseArrayLiteral
384− , P.try parseObjectLiteral
379+ , Literal <$> parseNumericLiteral
380+ , Literal <$> parseCharLiteral
381+ , Literal <$> parseStringLiteral
382+ , Literal <$> parseBooleanLiteral
383+ , Literal <$> parseArrayLiteral parseValue
384+ , Literal <$> P.try (parseObjectLiteral parseIdentifierAndValue)
385385 , parseAbs
386386 , P.try parseConstructor
387387 , P.try parseVar
@@ -469,17 +469,8 @@ parseUpdaterBody v = ObjectUpdate v <$> (C.indented *> braces (commaSep1 (C.inde
469469parseAnonymousArgument :: TokenParser Expr
470470parseAnonymousArgument = underscore *> pure AnonymousArgument
471471
472−parseStringBinder :: TokenParser Binder
473−parseStringBinder = StringBinder <$> stringLiteral
474−
475−parseCharBinder :: TokenParser Binder
476−parseCharBinder = CharBinder <$> charLiteral
477−
478−parseBooleanBinder :: TokenParser Binder
479−parseBooleanBinder = BooleanBinder <$> booleanLiteral
480−
481−parseNumberBinder :: TokenParser Binder
482−parseNumberBinder = NumberBinder <$> (sign <*> number)
472+parseNumberLiteral :: TokenParser Binder
473+parseNumberLiteral = LiteralBinder . NumericLiteral <$> (sign <*> number)
483474 where
484475 sign :: TokenParser (Either Integer Double -> Either Integer Double)
485476 sign = (symbol' "-" >> return (negate +++ negate))
@@ -492,11 +483,11 @@ parseNullaryConstructorBinder = ConstructorBinder <$> C.parseQualified C.properN
492483parseConstructorBinder :: TokenParser Binder
493484parseConstructorBinder = ConstructorBinder <$> C.parseQualified C.properName <*> many (C.indented *> parseBinderNoParens)
494485
495−parseObjectBinder :: TokenParser Binder
496−parseObjectBinder = ObjectBinder <$> braces (commaSep (C.indented *> parseIdentifierAndBinder))
486+parseObjectBinder:: TokenParser Binder
487+parseObjectBinder= LiteralBinder <$> parseObjectLiteral (C.indented *> parseIdentifierAndBinder)
497488
498489parseArrayBinder :: TokenParser Binder
499−parseArrayBinder = squares $ ArrayBinder <$> commaSep (C.indented *> parseBinder)
490+parseArrayBinder = LiteralBinder <$> parseArrayLiteral (C.indented *> parseBinder)
500491
501492parseVarOrNamedBinder :: TokenParser Binder
502493parseVarOrNamedBinder = do
@@ -541,10 +532,10 @@ parseBinder =
541532 parseBinderAtom :: TokenParser Binder
542533 parseBinderAtom = P.choice
543534 [ parseNullBinder
544− , parseCharBinder
545− , parseStringBinder
546− , parseBooleanBinder
547− , parseNumberBinder
535+ , LiteralBinder <$> parseCharLiteral
536+ , LiteralBinder <$> parseStringLiteral
537+ , LiteralBinder <$> parseBooleanLiteral
538+ , parseNumberLiteral
548539 , parseVarOrNamedBinder
549540 , parseConstructorBinder
550541 , parseObjectBinder
@@ -561,10 +552,10 @@ parseBinder =
561552parseBinderNoParens :: TokenParser Binder
562553parseBinderNoParens = P.choice
563554 [ parseNullBinder
564− , parseCharBinder
565− , parseStringBinder
566− , parseBooleanBinder
567− , parseNumberBinder
555+ , LiteralBinder <$> parseCharLiteral
556+ , LiteralBinder <$> parseStringLiteral
557+ , LiteralBinder <$> parseBooleanLiteral
558+ , parseNumberLiteral
568559 , parseVarOrNamedBinder
569560 , parseNullaryConstructorBinder
570561 , parseObjectBinder
src/Language/PureScript/Parser/JS.hs+1−1
@@ -36,7 +36,7 @@ import qualified Text.Parsec as PS
3636
3737type ForeignJS = String
3838
39−parseForeignModulesFromFiles :: (Functor m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
39+parseForeignModulesFromFiles :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
4040 => [(FilePath, ForeignJS)]
4141 -> m (M.Map ModuleName FilePath)
4242parseForeignModulesFromFiles files = do
src/Language/PureScript/Pretty/Values.hs+48−31
@@ -1,18 +1,6 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.Pretty.Values
4−-- Copyright : (c) Phil Freeman 2013
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
111-- |
122-- Pretty printer for values
133--
14−-----------------------------------------------------------------------------
15−
164module Language.PureScript.Pretty.Values (
175 prettyPrintValue,
186 prettyPrintBinder,
@@ -57,6 +45,7 @@ prettyPrintValue d (Accessor prop val) = prettyPrintValueAtom (d - 1) val <> tex
5745prettyPrintValue d (ObjectUpdate o ps) = prettyPrintValueAtom (d - 1) o <> text " " <> list '{' '}' (\(key, val) -> text (key ++ " = ") <> prettyPrintValue (d - 1) val) ps
5846prettyPrintValue d (App val arg) = prettyPrintValueAtom (d - 1) val `beforeWithSpace` prettyPrintValueAtom (d - 1) arg
5947prettyPrintValue d (Abs (Left arg) val) = text ('\\' : showIdent arg ++ " -> ") // moveRight 2 (prettyPrintValue (d - 1) val)
48+prettyPrintValue d (Abs (Right arg) val) = text ('\\' : prettyPrintBinder arg ++ " -> ") // moveRight 2 (prettyPrintValue (d - 1) val)
6049prettyPrintValue d (TypeClassDictionaryConstructorApp className ps) =
6150 text (runProperName (disqualify className) ++ " ") <> prettyPrintValueAtom (d - 1) ps
6251prettyPrintValue d (Case values binders) =
@@ -70,28 +59,49 @@ prettyPrintValue d (Do els) =
7059 text "do " <> vcat left (map (prettyPrintDoNotationElement (d - 1)) els)
7160prettyPrintValue _ (TypeClassDictionary (name, tys) _) = foldl1 beforeWithSpace $ text ("#dict " ++ runProperName (disqualify name)) : map typeAtomAsBox tys
7261prettyPrintValue _ (SuperClassDictionary name _) = text $ "#dict " ++ runProperName (disqualify name)
62+prettyPrintValue _ (TypeClassDictionaryAccessor className ident) =
63+ text "#dict-accessor " <> text (runProperName (disqualify className)) <> text "." <> text (showIdent ident) <> text ">"
7364prettyPrintValue d (TypedValue _ val _) = prettyPrintValue d val
7465prettyPrintValue d (PositionedValue _ _ val) = prettyPrintValue d val
75−prettyPrintValue d expr = prettyPrintValueAtom d expr
66+prettyPrintValue d (Literal l) = prettyPrintLiteralValue d l
67+prettyPrintValue d expr@AnonymousArgument{} = prettyPrintValueAtom d expr
68+prettyPrintValue d expr@Constructor{} = prettyPrintValueAtom d expr
69+prettyPrintValue d expr@Var{} = prettyPrintValueAtom d expr
70+prettyPrintValue d expr@OperatorSection{} = prettyPrintValueAtom d expr
71+prettyPrintValue d expr@BinaryNoParens{} = prettyPrintValueAtom d expr
72+prettyPrintValue d expr@Parens{} = prettyPrintValueAtom d expr
73+prettyPrintValue d expr@UnaryMinus{} = prettyPrintValueAtom d expr
74+prettyPrintValue d expr@ObjectGetter{} = prettyPrintValueAtom d expr
7675
7776-- | Pretty-print an atomic expression, adding parentheses if necessary.
7877prettyPrintValueAtom :: Int -> Expr -> Box
79−prettyPrintValueAtom _ (NumericLiteral n) = text $ either show show n
80−prettyPrintValueAtom _ (StringLiteral s) = text $ show s
81−prettyPrintValueAtom _ (CharLiteral c) = text $ show c
82−prettyPrintValueAtom _ (BooleanLiteral True) = text "true"
83−prettyPrintValueAtom _ (BooleanLiteral False) = text "false"
84−prettyPrintValueAtom d (ArrayLiteral xs) = list '[' ']' (prettyPrintValue (d - 1)) xs
85−prettyPrintValueAtom d (ObjectLiteral ps) = prettyPrintObject (d - 1) $ second Just `map` ps
78+prettyPrintValueAtom d (Literal l) = prettyPrintLiteralValue d l
8679prettyPrintValueAtom _ AnonymousArgument = text "_"
8780prettyPrintValueAtom _ (Constructor name) = text $ runProperName (disqualify name)
8881prettyPrintValueAtom _ (Var ident) = text $ showIdent (disqualify ident)
8982prettyPrintValueAtom d (OperatorSection op (Right val)) = ((text "(" <> prettyPrintValue (d - 1) op) `beforeWithSpace` prettyPrintValue (d - 1) val) `before` text ")"
9083prettyPrintValueAtom d (OperatorSection op (Left val)) = ((text "(" <> prettyPrintValue (d - 1) val) `beforeWithSpace` prettyPrintValue (d - 1) op) `before` text ")"
84+prettyPrintValueAtom d (BinaryNoParens op lhs rhs) =
85+ prettyPrintValue (d - 1) lhs `beforeWithSpace` printOp op `beforeWithSpace` prettyPrintValue (d - 1) rhs
86+ where
87+ printOp (Var (Qualified _ (Op opName))) = text opName
88+ printOp expr = text "`" <> prettyPrintValue (d - 1) expr <> text "`"
9189prettyPrintValueAtom d (TypedValue _ val _) = prettyPrintValueAtom d val
9290prettyPrintValueAtom d (PositionedValue _ _ val) = prettyPrintValueAtom d val
91+prettyPrintValueAtom d (Parens expr) = (text "(" <> prettyPrintValue d expr) `before` text ")"
92+prettyPrintValueAtom d (UnaryMinus expr) = text "(-" <> prettyPrintValue d expr <> text ")"
93+prettyPrintValueAtom _ (ObjectGetter field) = text "_." <> text field
9394prettyPrintValueAtom d expr = (text "(" <> prettyPrintValue d expr) `before` text ")"
9495
96+prettyPrintLiteralValue :: Int -> Literal Expr -> Box
97+prettyPrintLiteralValue _ (NumericLiteral n) = text $ either show show n
98+prettyPrintLiteralValue _ (StringLiteral s) = text $ show s
99+prettyPrintLiteralValue _ (CharLiteral c) = text $ show c
100+prettyPrintLiteralValue _ (BooleanLiteral True) = text "true"
101+prettyPrintLiteralValue _ (BooleanLiteral False) = text "false"
102+prettyPrintLiteralValue d (ArrayLiteral xs) = list '[' ']' (prettyPrintValue (d - 1)) xs
103+prettyPrintLiteralValue d (ObjectLiteral ps) = prettyPrintObject (d - 1) $ second Just `map` ps
104+
95105prettyPrintDeclaration :: Int -> Declaration -> Box
96106prettyPrintDeclaration d _ | d < 0 = ellipsis
97107prettyPrintDeclaration _ (TypeDeclaration ident ty) =
@@ -136,28 +146,35 @@ prettyPrintDoNotationElement d (PositionedDoNotationElement _ _ el) = prettyPrin
136146
137147prettyPrintBinderAtom :: Binder -> String
138148prettyPrintBinderAtom NullBinder = "_"
139−prettyPrintBinderAtom (StringBinder str) = show str
140−prettyPrintBinderAtom (CharBinder c) = show c
141−prettyPrintBinderAtom (NumberBinder num) = either show show num
142−prettyPrintBinderAtom (BooleanBinder True) = "true"
143−prettyPrintBinderAtom (BooleanBinder False) = "false"
149+prettyPrintBinderAtom (LiteralBinder l) = prettyPrintLiteralBinder l
144150prettyPrintBinderAtom (VarBinder ident) = showIdent ident
145151prettyPrintBinderAtom (ConstructorBinder ctor []) = runProperName (disqualify ctor)
146−prettyPrintBinderAtom (ObjectBinder bs) =
152+prettyPrintBinderAtom b@ConstructorBinder{} = parens (prettyPrintBinder b)
153+prettyPrintBinderAtom (NamedBinder ident binder) = showIdent ident ++ "@" ++ prettyPrintBinder binder
154+prettyPrintBinderAtom (PositionedBinder _ _ binder) = prettyPrintBinderAtom binder
155+prettyPrintBinderAtom (TypedBinder _ binder) = prettyPrintBinderAtom binder
156+prettyPrintBinderAtom (OpBinder op) = showIdent (disqualify op)
157+prettyPrintBinderAtom (BinaryNoParensBinder op b1 b2) =
158+ prettyPrintBinderAtom b1 ++ " " ++ prettyPrintBinderAtom op ++ " " ++ prettyPrintBinderAtom b2
159+prettyPrintBinderAtom (ParensInBinder b) = parens (prettyPrintBinder b)
160+
161+prettyPrintLiteralBinder :: Literal Binder -> String
162+prettyPrintLiteralBinder (StringLiteral str) = show str
163+prettyPrintLiteralBinder (CharLiteral c) = show c
164+prettyPrintLiteralBinder (NumericLiteral num) = either show show num
165+prettyPrintLiteralBinder (BooleanLiteral True) = "true"
166+prettyPrintLiteralBinder (BooleanLiteral False) = "false"
167+prettyPrintLiteralBinder (ObjectLiteral bs) =
147168 "{ "
148169 ++ intercalate ", " (map prettyPrintObjectPropertyBinder bs)
149170 ++ " }"
150171 where
151172 prettyPrintObjectPropertyBinder :: (String, Binder) -> String
152173 prettyPrintObjectPropertyBinder (key, binder) = prettyPrintObjectKey key ++ ": " ++ prettyPrintBinder binder
153−prettyPrintBinderAtom (ArrayBinder bs) =
174+prettyPrintLiteralBinder (ArrayLiteral bs) =
154175 "[ "
155176 ++ intercalate ", " (map prettyPrintBinder bs)
156177 ++ " ]"
157−prettyPrintBinderAtom (NamedBinder ident binder) = showIdent ident ++ "@" ++ prettyPrintBinder binder
158−prettyPrintBinderAtom (PositionedBinder _ _ binder) = prettyPrintBinderAtom binder
159−prettyPrintBinderAtom (TypedBinder _ binder) = prettyPrintBinderAtom binder
160−prettyPrintBinderAtom b = parens (prettyPrintBinder b)
161178
162179-- |
163180-- Generate a pretty-printed string representing a Binder
src/Language/PureScript/Publish/ErrorsWarnings.hs+1−1
@@ -190,7 +190,7 @@ displayUserError e = case e of
190190 CompileError err ->
191191 vcat
192192 [ para "Compile error:"
193− , indented (P.prettyPrintMultipleErrorsBox False err)
193+ , indented (vcat (P.prettyPrintMultipleErrorsBox False err))
194194 ]
195195 DirtyWorkingTree ->
196196 para (
src/Language/PureScript/Sugar.hs+1−1
@@ -63,7 +63,7 @@ import Language.PureScript.Sugar.TypeDeclarations as S
6363--
6464-- * Group mutually recursive value and data declarations into binding groups.
6565--
66−desugar :: (Applicative m, MonadSupply m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [ExternsFile] -> [Module] -> m [Module]
66+desugar :: (MonadSupply m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [ExternsFile] -> [Module] -> m [Module]
6767desugar externs =
6868 map removeSignedLiterals
6969 >>> traverse desugarObjectConstructors
src/Language/PureScript/Sugar/BindingGroups.hs+3−3
@@ -35,7 +35,7 @@ import Language.PureScript.Types
3535-- Replace all sets of mutually-recursive declarations in a module with binding groups
3636--
3737createBindingGroupsModule
38− :: (Functor m, Applicative m, MonadError MultipleErrors m)
38+ :: (MonadError MultipleErrors m)
3939 => [Module]
4040 -> m [Module]
4141createBindingGroupsModule =
@@ -52,7 +52,7 @@ collapseBindingGroupsModule =
5252
5353createBindingGroups
5454 :: forall m
55− . (Functor m, Applicative m, MonadError MultipleErrors m)
55+ . (MonadError MultipleErrors m)
5656 => ModuleName
5757 -> [Declaration]
5858 -> m [Declaration]
@@ -171,7 +171,7 @@ getTypeName _ = internalError "Expected DataDeclaration"
171171--
172172toBindingGroup
173173 :: forall m
174− . (Functor m, MonadError MultipleErrors m)
174+ . (MonadError MultipleErrors m)
175175 => ModuleName
176176 -> SCC Declaration
177177 -> m Declaration
src/Language/PureScript/Sugar/CaseDeclarations.hs+6−6
@@ -36,7 +36,7 @@ isLeft (Right _) = False
3636-- |
3737-- Replace all top-level binders in a module with case expressions.
3838--
39−desugarCasesModule :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [Module] -> m [Module]
39+desugarCasesModule :: (MonadSupply m, MonadError MultipleErrors m) => [Module] -> m [Module]
4040desugarCasesModule ms = forM ms $ \(Module ss coms name ds exps) ->
4141 rethrow (addHint (ErrorInModule name)) $
4242 Module ss coms name <$> (desugarCases <=< desugarAbs <=< validateCases $ ds) <*> pure exps
@@ -44,7 +44,7 @@ desugarCasesModule ms = forM ms $ \(Module ss coms name ds exps) ->
4444-- |
4545-- Validates that case head and binder lengths match.
4646--
47−validateCases :: forall m. (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
47+validateCases :: forall m. (MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
4848validateCases = flip parU f
4949 where
5050 (f, _, _) = everywhereOnValuesM return validate return
@@ -69,7 +69,7 @@ validateCases = flip parU f
6969 positionedBinder (PositionedBinder p _ _) = Just p
7070 positionedBinder _ = Nothing
7171
72−desugarAbs :: forall m. (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
72+desugarAbs :: forall m. (MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
7373desugarAbs = flip parU f
7474 where
7575 (f, _, _) = everywhereOnValuesM return replace return
@@ -83,7 +83,7 @@ desugarAbs = flip parU f
8383-- |
8484-- Replace all top-level binders with case expressions.
8585--
86−desugarCases :: forall m. (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
86+desugarCases :: forall m. (MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
8787desugarCases = desugarRest <=< fmap join . flip parU toDecls . groupBy inSameGroup
8888 where
8989 desugarRest :: [Declaration] -> m [Declaration]
@@ -109,7 +109,7 @@ inSameGroup (PositionedDeclaration _ _ d1) d2 = inSameGroup d1 d2
109109inSameGroup d1 (PositionedDeclaration _ _ d2) = inSameGroup d1 d2
110110inSameGroup _ _ = False
111111
112−toDecls :: forall m. (Functor m, Applicative m, Monad m, MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
112+toDecls :: forall m. (MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
113113toDecls [ValueDeclaration ident nameKind bs (Right val)] | all isVarBinder bs = do
114114 args <- mapM fromVarBinder bs
115115 let body = foldr (Abs . Left) val args
@@ -147,7 +147,7 @@ toTuple (ValueDeclaration _ _ bs result) = (bs, result)
147147toTuple (PositionedDeclaration _ _ d) = toTuple d
148148toTuple _ = internalError "Not a value declaration"
149149
150−makeCaseDeclaration :: forall m. (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => Ident -> [([Binder], Either [(Guard, Expr)] Expr)] -> m Declaration
150+makeCaseDeclaration :: forall m. (MonadSupply m, MonadError MultipleErrors m) => Ident -> [([Binder], Either [(Guard, Expr)] Expr)] -> m Declaration
151151makeCaseDeclaration ident alternatives = do
152152 let namedArgs = map findName . fst <$> alternatives
153153 argNames = foldl1 resolveNames namedArgs
src/Language/PureScript/Sugar/DoNotation.hs+2−2
@@ -26,10 +26,10 @@ import Control.Monad.Supply.Class
2626-- Replace all @DoNotationBind@ and @DoNotationValue@ constructors with applications of the Prelude.bind function,
2727-- and all @DoNotationLet@ constructors with let expressions.
2828--
29−desugarDoModule :: forall m. (Applicative m, MonadSupply m, MonadError MultipleErrors m) => Module -> m Module
29+desugarDoModule :: forall m. (MonadSupply m, MonadError MultipleErrors m) => Module -> m Module
3030desugarDoModule (Module ss coms mn ds exts) = Module ss coms mn <$> parU ds desugarDo <*> pure exts
3131
32−desugarDo :: forall m. (Applicative m, MonadSupply m, MonadError MultipleErrors m) => Declaration -> m Declaration
32+desugarDo :: forall m. (MonadSupply m, MonadError MultipleErrors m) => Declaration -> m Declaration
3333desugarDo (PositionedDeclaration pos com d) = PositionedDeclaration pos com <$> rethrowWithPosition pos (desugarDo d)
3434desugarDo d =
3535 let (f, _, _) = everywhereOnValuesM return replace return
src/Language/PureScript/Sugar/Names.hs+4−4
@@ -44,13 +44,13 @@ import Language.PureScript.Linter.Imports
4444-- Replaces all local names with qualified names within a list of modules. The
4545-- modules should be topologically sorted beforehand.
4646--
47−desugarImports :: forall m. (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [ExternsFile] -> [Module] -> m [Module]
47+desugarImports :: forall m. (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => [ExternsFile] -> [Module] -> m [Module]
4848desugarImports externs modules =
4949 fmap snd (desugarImportsWithEnv externs modules)
5050
5151desugarImportsWithEnv
5252 :: forall m
53− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
53+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
5454 => [ExternsFile]
5555 -> [Module]
5656 -> m (Env, [Module])
@@ -141,7 +141,7 @@ elaborateExports exps (Module ss coms mn decls refs) =
141141--
142142renameInModule
143143 :: forall m
144− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadState UsedImports m)
144+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadState UsedImports m)
145145 => Env
146146 -> Imports
147147 -> Module
@@ -334,7 +334,7 @@ renameInModule env imports (Module ss coms mn decls exps) =
334334--
335335updateExportRefs
336336 :: forall m
337− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
337+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
338338 => Module
339339 -> m Module
340340updateExportRefs (Module ss coms mn decls exps) =
src/Language/PureScript/Sugar/Names/Exports.hs+3−3
@@ -31,7 +31,7 @@ import Language.PureScript.Sugar.Names.Env
3131-- |
3232-- Finds all exportable members of a module, disregarding any explicit exports.
3333--
34−findExportable :: forall m. (Applicative m, MonadError MultipleErrors m) => Module -> m Exports
34+findExportable :: forall m. (MonadError MultipleErrors m) => Module -> m Exports
3535findExportable (Module _ _ mn ds _) =
3636 rethrow (addHint (ErrorInModule mn)) $ foldM updateExports nullExports ds
3737 where
@@ -56,7 +56,7 @@ findExportable (Module _ _ mn ds _) =
5656-- Resolves the exports for a module, filtering out members that have not been
5757-- exported and elaborating re-exports of other modules.
5858--
59−resolveExports :: forall m. (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => Env -> ModuleName -> Imports -> Exports -> [DeclarationRef] -> m Exports
59+resolveExports :: forall m. (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => Env -> ModuleName -> Imports -> Exports -> [DeclarationRef] -> m Exports
6060resolveExports env mn imps exps refs =
6161 rethrow (addHint (ErrorInModule mn)) $ do
6262 filtered <- filterModule mn exps refs
@@ -199,7 +199,7 @@ resolveExports env mn imps exps refs =
199199--
200200filterModule
201201 :: forall m
202− . (Applicative m, MonadError MultipleErrors m)
202+ . (MonadError MultipleErrors m)
203203 => ModuleName
204204 -> Exports
205205 -> [DeclarationRef]
src/Language/PureScript/Sugar/Names/Imports.hs+4−4
@@ -37,7 +37,7 @@ import Language.PureScript.Sugar.Names.Env
3737--
3838findImports
3939 :: forall m
40− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
40+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
4141 => [Declaration]
4242 -> m (M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)])
4343findImports = foldM (go Nothing) M.empty
@@ -56,7 +56,7 @@ type ImportDef = (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)
5656--
5757resolveImports
5858 :: forall m
59− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
59+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
6060 => Env
6161 -> Module
6262 -> m (Module, Imports)
@@ -160,7 +160,7 @@ resolveImports env (Module ss coms currentModule decls exps) =
160160-- | Constructs a set of imports for a single module import.
161161resolveModuleImport
162162 :: forall m
163− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
163+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
164164 => Env
165165 -> Imports
166166 -> (ModuleName, [(Maybe SourceSpan, Maybe ImportDeclarationType, Maybe ModuleName)])
@@ -187,7 +187,7 @@ resolveModuleImport env ie (mn, imps) = foldM go ie imps
187187--
188188resolveImport
189189 :: forall m
190− . (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
190+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m)
191191 => ModuleName
192192 -> Exports
193193 -> Imports
src/Language/PureScript/Sugar/ObjectWildcards.hs+6−2
@@ -19,7 +19,11 @@ import Language.PureScript.AST
1919import Language.PureScript.Errors
2020import Language.PureScript.Names
2121
22−desugarObjectConstructors :: forall m. (Applicative m, MonadSupply m, MonadError MultipleErrors m) => Module -> m Module
22+desugarObjectConstructors
23+ :: forall m
24+ . (MonadSupply m, MonadError MultipleErrors m)
25+ => Module
26+ -> m Module
2327desugarObjectConstructors (Module ss coms mn ds exts) = Module ss coms mn <$> mapM desugarDecl ds <*> pure exts
2428 where
2529
@@ -38,7 +42,7 @@ desugarObjectConstructors (Module ss coms mn ds exts) = Module ss coms mn <$> ma
3842 | b' <- stripPositionInfo b
3943 , BinaryNoParens op u val <- b'
4044 , isAnonymousArgument u = return $ OperatorSection op (Right val)
41− desugarExpr (ObjectLiteral ps) = wrapLambda ObjectLiteral ps
45+ desugarExpr (Literal (ObjectLiteral ps)) = wrapLambda (Literal . ObjectLiteral) ps
4246 desugarExpr (ObjectUpdate u ps) | isAnonymousArgument u = do
4347 obj <- freshIdent'
4448 Abs (Left obj) <$> wrapLambda (ObjectUpdate (Var (Qualified Nothing obj))) ps
src/Language/PureScript/Sugar/Operators.hs+9−6
@@ -57,7 +57,7 @@ type AliasName = Either (Qualified Ident) (Qualified (ProperName 'ConstructorNam
5757--
5858rebracket
5959 :: forall m
60− . (Applicative m, MonadError MultipleErrors m)
60+ . (MonadError MultipleErrors m)
6161 => [ExternsFile]
6262 -> [Module]
6363 -> m [Module]
@@ -116,7 +116,7 @@ removeSignedLiterals (Module ss coms mn ds exts) = Module ss coms mn (map f' ds)
116116 go other = other
117117
118118rebracketModule
119− :: (Applicative m, MonadError MultipleErrors m)
119+ :: (MonadError MultipleErrors m)
120120 => [[(Qualified Ident, Associativity)]]
121121 -> Module
122122 -> m Module
@@ -178,7 +178,7 @@ customOperatorTable fixities =
178178
179179desugarOperatorSections
180180 :: forall m
181− . (Applicative m, MonadSupply m, MonadError MultipleErrors m)
181+ . (MonadSupply m, MonadError MultipleErrors m)
182182 => Module
183183 -> m Module
184184desugarOperatorSections (Module ss coms mn ds exts) =
@@ -189,8 +189,11 @@ desugarOperatorSections (Module ss coms mn ds exts) =
189189 (goDecl, _, _) = everywhereOnValuesM return goExpr return
190190
191191 goExpr :: Expr -> m Expr
192− goExpr (OperatorSection op (Left val)) = return $ App op val
193− goExpr (OperatorSection op (Right val)) = do
192+ goExpr (OperatorSection op eVal) = do
194193 arg <- freshIdent'
195− return $ Abs (Left arg) $ App (App op (Var (Qualified Nothing arg))) val
194+ let var = Var (Qualified Nothing arg)
195+ f2 a b = Abs (Left arg) $ App (App op a) b
196+ return $ case eVal of
197+ Left val -> f2 val var
198+ Right val -> f2 var val
196199 goExpr other = return other
src/Language/PureScript/Sugar/TypeClasses.hs+5−5
@@ -45,7 +45,7 @@ type Desugar = StateT MemberMap
4545-- instance dictionary expressions.
4646--
4747desugarTypeClasses
48− :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m)
48+ :: (MonadSupply m, MonadError MultipleErrors m)
4949 => [ExternsFile]
5050 -> [Module]
5151 -> m [Module]
@@ -62,7 +62,7 @@ desugarTypeClasses externs = flip evalStateT initialState . traverse desugarModu
6262 fromExternsDecl _ _ = Nothing
6363
6464desugarModule
65− :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m)
65+ :: (MonadSupply m, MonadError MultipleErrors m)
6666 => Module
6767 -> Desugar m Module
6868desugarModule (Module ss coms name decls (Just exps)) = do
@@ -171,7 +171,7 @@ desugarModule _ = internalError "Exports should have been elaborated in name des
171171-- };
172172-}
173173desugarDecl
174− :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m)
174+ :: (MonadSupply m, MonadError MultipleErrors m)
175175 => ModuleName
176176 -> [DeclarationRef]
177177 -> Declaration
@@ -259,7 +259,7 @@ unit = TypeApp tyObject REmpty
259259
260260typeInstanceDictionaryDeclaration
261261 :: forall m
262− . (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m)
262+ . (MonadSupply m, MonadError MultipleErrors m)
263263 => Ident
264264 -> ModuleName
265265 -> [Constraint]
@@ -297,7 +297,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
297297 , let tyArgs = map (replaceAllTypeVars (zip (map fst args) tys)) suTyArgs
298298 ]
299299
300− let props = ObjectLiteral (members ++ superclasses)
300+ let props = Literal $ ObjectLiteral (members ++ superclasses)
301301 dictTy = foldl TypeApp (TypeConstructor (fmap coerceProperName className)) tys
302302 constrainedTy = quantify (if null deps then dictTy else ConstrainedType deps dictTy)
303303 dict = TypeClassDictionaryConstructorApp className props
src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+55−35
@@ -32,7 +32,7 @@ import qualified Language.PureScript.Constants as C
3232
3333-- | Elaborates deriving instance declarations by code generation.
3434deriveInstances
35− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadSupply m)
35+ :: (MonadError MultipleErrors m, MonadSupply m)
3636 => Module
3737 -> m Module
3838deriveInstances (Module ss coms mn ds exts) = Module ss coms mn <$> mapM (deriveInstance mn ds) ds <*> pure exts
@@ -40,7 +40,7 @@ deriveInstances (Module ss coms mn ds exts) = Module ss coms mn <$> mapM (derive
4040-- | Takes a declaration, and if the declaration is a deriving TypeInstanceDeclaration,
4141-- elaborates that into an instance declaration via code generation.
4242deriveInstance
43− :: (Functor m, MonadError MultipleErrors m, MonadSupply m)
43+ :: (MonadError MultipleErrors m, MonadSupply m)
4444 => ModuleName
4545 -> [Declaration]
4646 -> Declaration
@@ -82,7 +82,7 @@ typesProxy :: ModuleName
8282typesProxy = ModuleName [ ProperName "Type", ProperName "Proxy" ]
8383
8484deriveGeneric
85− :: forall m. (Functor m, MonadError MultipleErrors m, MonadSupply m)
85+ :: forall m. (MonadError MultipleErrors m, MonadSupply m)
8686 => ModuleName
8787 -> [Declaration]
8888 -> ProperName 'TypeName
@@ -115,15 +115,21 @@ deriveGeneric mn ds tyConNm dargs = do
115115 return $ CaseAlternative [ConstructorBinder (Qualified (Just mn) ctorName) (map VarBinder idents)] (Right (caseResult idents))
116116 where
117117 caseResult idents =
118− App (prodConstructor (StringLiteral . showQualified runProperName $ Qualified (Just mn) ctorName))
119− . ArrayLiteral
118+ App (prodConstructor (Literal . StringLiteral . showQualified runProperName $ Qualified (Just mn) ctorName))
119+ . Literal . ArrayLiteral
120120 $ zipWith toSpineFun (map (Var . Qualified Nothing) idents) tys
121121
122122 toSpineFun :: Expr -> Type -> Expr
123123 toSpineFun i r | Just rec <- objectType r =
124− lamNull . recordConstructor . ArrayLiteral .
125− map (\(str,typ) -> ObjectLiteral [("recLabel", StringLiteral str), ("recValue", toSpineFun (Accessor str i) typ)])
126− $ decomposeRec rec
124+ lamNull . recordConstructor . Literal . ArrayLiteral
125+ . map
126+ (\(str,typ) ->
127+ Literal $ ObjectLiteral
128+ [ ("recLabel", Literal (StringLiteral str))
129+ , ("recValue", toSpineFun (Accessor str i) typ)
130+ ]
131+ )
132+ $ decomposeRec rec
127133 toSpineFun i _ = lamNull $ App (mkGenVar (Ident C.toSpine)) i
128134 mkSpineFunction (PositionedDeclaration _ _ d) = mkSpineFunction d
129135 mkSpineFunction _ = internalError "mkSpineFunction: expected DataDeclaration"
@@ -132,30 +138,37 @@ deriveGeneric mn ds tyConNm dargs = do
132138 mkSignatureFunction (DataDeclaration _ name tyArgs args) classArgs = lamNull . mkSigProd $ map mkProdClause args
133139 where
134140 mkSigProd :: [Expr] -> Expr
135− mkSigProd = App (App (Constructor (Qualified (Just dataGeneric) (ProperName "SigProd")))
136− (StringLiteral (showQualified runProperName (Qualified (Just mn) name)))
137− ) . ArrayLiteral
141+ mkSigProd =
142+ App
143+ (App
144+ (Constructor (Qualified (Just dataGeneric) (ProperName "SigProd")))
145+ (Literal (StringLiteral (showQualified runProperName (Qualified (Just mn) name))))
146+ )
147+ . Literal
148+ . ArrayLiteral
138149
139150 mkSigRec :: [Expr] -> Expr
140− mkSigRec = App (Constructor (Qualified (Just dataGeneric) (ProperName "SigRecord"))) . ArrayLiteral
151+ mkSigRec = App (Constructor (Qualified (Just dataGeneric) (ProperName "SigRecord"))) . Literal . ArrayLiteral
141152
142153 proxy :: Type -> Type
143154 proxy = TypeApp (TypeConstructor (Qualified (Just typesProxy) (ProperName "Proxy")))
144155
145156 mkProdClause :: (ProperName 'ConstructorName, [Type]) -> Expr
146157 mkProdClause (ctorName, tys) =
147− ObjectLiteral
148− [ ("sigConstructor", StringLiteral (showQualified runProperName (Qualified (Just mn) ctorName)))
149− , ("sigValues", ArrayLiteral . map (mkProductSignature . instantiate) $ tys)
158+ Literal $ ObjectLiteral
159+ [ ("sigConstructor", Literal (StringLiteral (showQualified runProperName (Qualified (Just mn) ctorName))))
160+ , ("sigValues", Literal . ArrayLiteral . map (mkProductSignature . instantiate) $ tys)
150161 ]
151162
152163 mkProductSignature :: Type -> Expr
153164 mkProductSignature r | Just rec <- objectType r =
154− lamNull . mkSigRec $ [ ObjectLiteral [ ("recLabel", StringLiteral str)
155− , ("recValue", mkProductSignature typ)
156− ]
157− | (str, typ) <- decomposeRec rec
158− ]
165+ lamNull . mkSigRec $
166+ [ Literal $ ObjectLiteral
167+ [ ("recLabel", Literal (StringLiteral str))
168+ , ("recValue", mkProductSignature typ)
169+ ]
170+ | (str, typ) <- decomposeRec rec
171+ ]
159172 mkProductSignature typ = lamNull $ App (mkGenVar (Ident C.toSignature))
160173 (TypedValue False (mkGenVar (Ident "anyProxy")) (proxy typ))
161174 instantiate = replaceAllTypeVars (zipWith (\(arg, _) ty -> (arg, ty)) tyArgs classArgs)
@@ -182,10 +195,17 @@ deriveGeneric mn ds tyConNm dargs = do
182195 mkAlternative :: (ProperName 'ConstructorName, [Type]) -> m CaseAlternative
183196 mkAlternative (ctorName, tys) = do
184197 idents <- replicateM (length tys) freshIdent'
185− return $ CaseAlternative [ prodBinder [ StringBinder (showQualified runProperName (Qualified (Just mn) ctorName)), ArrayBinder (map VarBinder idents)]]
186− . Right
187− $ liftApplicative (mkJust $ Constructor (Qualified (Just mn) ctorName))
188− (zipWith fromSpineFun (map (Var . Qualified Nothing) idents) tys)
198+ return $
199+ CaseAlternative
200+ [ prodBinder
201+ [ LiteralBinder (StringLiteral (showQualified runProperName (Qualified (Just mn) ctorName)))
202+ , LiteralBinder (ArrayLiteral (map VarBinder idents))
203+ ]
204+ ]
205+ . Right
206+ $ liftApplicative
207+ (mkJust $ Constructor (Qualified (Just mn) ctorName))
208+ (zipWith fromSpineFun (map (Var . Qualified Nothing) idents) tys)
189209
190210 addCatch :: [CaseAlternative] -> [CaseAlternative]
191211 addCatch = (++ [catchAll])
@@ -202,15 +222,15 @@ deriveGeneric mn ds tyConNm dargs = do
202222 fromSpineFun e _ = App (mkGenVar (Ident C.fromSpine)) (App e (mkPrelVar (Ident "unit")))
203223
204224 mkRecCase :: [(String, Type)] -> CaseAlternative
205− mkRecCase rs = CaseAlternative [ recordBinder [ ArrayBinder (map (VarBinder . Ident . fst) rs)
206− ]
207− ]
208− . Right
209− $ liftApplicative (mkRecFun rs) (map (\(x, y) -> fromSpineFun (Accessor "recValue" (mkVar (Ident x))) y) rs)
225+ mkRecCase rs =
226+ CaseAlternative
227+ [ recordBinder [ LiteralBinder (ArrayLiteral (map (VarBinder . Ident . fst) rs)) ] ]
228+ . Right
229+ $ liftApplicative (mkRecFun rs) (map (\(x, y) -> fromSpineFun (Accessor "recValue" (mkVar (Ident x))) y) rs)
210230
211231 mkRecFun :: [(String, Type)] -> Expr
212232 mkRecFun xs = mkJust $ foldr lam recLiteral (map (Ident . fst) xs)
213− where recLiteral = ObjectLiteral $ map (\(s,_) -> (s, mkVar (Ident s))) xs
233+ where recLiteral = Literal . ObjectLiteral $ map (\(s,_) -> (s, mkVar (Ident s))) xs
214234 mkFromSpineFunction (PositionedDeclaration _ _ d) = mkFromSpineFunction d
215235 mkFromSpineFunction _ = internalError "mkFromSpineFunction: expected DataDeclaration"
216236
@@ -226,7 +246,7 @@ deriveGeneric mn ds tyConNm dargs = do
226246 mkGenVar = mkVarMn (Just (ModuleName [ProperName "Data", ProperName C.generic]))
227247
228248deriveEq ::
229− forall m. (Functor m, MonadError MultipleErrors m, MonadSupply m)
249+ forall m. (MonadError MultipleErrors m, MonadSupply m)
230250 => ModuleName
231251 -> [Declaration]
232252 -> ProperName 'TypeName
@@ -255,7 +275,7 @@ deriveEq mn ds tyConNm = do
255275 | length xs /= 1 = xs ++ [catchAll]
256276 | otherwise = xs -- Avoid redundant case
257277 where
258− catchAll = CaseAlternative [NullBinder, NullBinder] (Right (BooleanLiteral False))
278+ catchAll = CaseAlternative [NullBinder, NullBinder] (Right (Literal (BooleanLiteral False)))
259279
260280 mkCtorClause :: (ProperName 'ConstructorName, [Type]) -> m CaseAlternative
261281 mkCtorClause (ctorName, tys) = do
@@ -267,7 +287,7 @@ deriveEq mn ds tyConNm = do
267287 caseBinder idents = ConstructorBinder (Qualified (Just mn) ctorName) (map VarBinder idents)
268288
269289 conjAll :: [Expr] -> Expr
270− conjAll [] = BooleanLiteral True
290+ conjAll [] = Literal (BooleanLiteral True)
271291 conjAll xs = foldl1 preludeConj xs
272292
273293 toEqTest :: Expr -> Expr -> Type -> Expr
@@ -278,7 +298,7 @@ deriveEq mn ds tyConNm = do
278298 toEqTest l r _ = preludeEq l r
279299
280300deriveOrd ::
281− forall m. (Functor m, MonadError MultipleErrors m, MonadSupply m)
301+ forall m. (MonadError MultipleErrors m, MonadSupply m)
282302 => ModuleName
283303 -> [Declaration]
284304 -> ProperName 'TypeName
@@ -357,7 +377,7 @@ deriveOrd mn ds tyConNm = do
357377 toOrdering l r _ = preludeCompare l r
358378
359379findTypeDecl
360− :: (Functor m, MonadError MultipleErrors m)
380+ :: (MonadError MultipleErrors m)
361381 => ProperName 'TypeName
362382 -> [Declaration]
363383 -> m Declaration
src/Language/PureScript/Sugar/TypeDeclarations.hs+1−1
@@ -36,7 +36,7 @@ import Language.PureScript.Traversals
3636-- |
3737-- Replace all top level type declarations in a module with type annotations
3838--
39−desugarTypeDeclarationsModule :: forall m. (Functor m, Applicative m, MonadError MultipleErrors m) => [Module] -> m [Module]
39+desugarTypeDeclarationsModule :: forall m. (MonadError MultipleErrors m) => [Module] -> m [Module]
4040desugarTypeDeclarationsModule ms = forM ms $ \(Module ss coms name ds exps) ->
4141 rethrow (addHint (ErrorInModule name)) $
4242 Module ss coms name <$> desugarTypeDeclarations ds <*> pure exps
src/Language/PureScript/TypeChecker.hs+12−12
@@ -40,7 +40,7 @@ import Language.PureScript.TypeClassDictionaries
4040import Language.PureScript.Types
4141
4242addDataType
43− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
43+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
4444 => ModuleName
4545 -> DataDeclType
4646 -> ProperName 'TypeName
@@ -56,7 +56,7 @@ addDataType moduleName dtype name args dctors ctorKind = do
5656 addDataConstructor moduleName dtype name (map fst args) dctor tys
5757
5858addDataConstructor
59− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
59+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
6060 => ModuleName
6161 -> DataDeclType
6262 -> ProperName 'TypeName
@@ -74,7 +74,7 @@ addDataConstructor moduleName dtype name args dctor tys = do
7474 putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) (dtype, name, polyType, fields) (dataConstructors env) }
7575
7676addTypeSynonym
77− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
77+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
7878 => ModuleName
7979 -> ProperName 'TypeName
8080 -> [(String, Maybe Kind)]
@@ -88,7 +88,7 @@ addTypeSynonym moduleName name args ty kind = do
8888 , typeSynonyms = M.insert (Qualified (Just moduleName) name) (args, ty) (typeSynonyms env) }
8989
9090valueIsNotDefined
91− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
91+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
9292 => ModuleName
9393 -> Ident
9494 -> m ()
@@ -99,7 +99,7 @@ valueIsNotDefined moduleName name = do
9999 Nothing -> return ()
100100
101101addValue
102− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
102+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
103103 => ModuleName
104104 -> Ident
105105 -> Type
@@ -110,7 +110,7 @@ addValue moduleName name ty nameKind = do
110110 putEnv (env { names = M.insert (moduleName, name) (ty, nameKind, Defined) (names env) })
111111
112112addTypeClass
113− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
113+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
114114 => ModuleName
115115 -> ProperName 'ClassName
116116 -> [(String, Maybe Kind)]
@@ -126,7 +126,7 @@ addTypeClass moduleName pn args implies ds =
126126 toPair _ = internalError "Invalid declaration in TypeClassDeclaration"
127127
128128addTypeClassDictionaries
129− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
129+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
130130 => Maybe ModuleName
131131 -> M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope)
132132 -> m ()
@@ -135,7 +135,7 @@ addTypeClassDictionaries mn entries =
135135 where insertState st = M.insertWith (M.unionWith M.union) mn entries (typeClassDictionaries . checkEnv $ st)
136136
137137checkDuplicateTypeArguments
138− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
138+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
139139 => [String]
140140 -> m ()
141141checkDuplicateTypeArguments args = for_ firstDup $ \dup ->
@@ -145,7 +145,7 @@ checkDuplicateTypeArguments args = for_ firstDup $ \dup ->
145145 firstDup = listToMaybe $ args \\ nub args
146146
147147checkTypeClassInstance
148− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
148+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
149149 => ModuleName
150150 -> Type
151151 -> m ()
@@ -161,7 +161,7 @@ checkTypeClassInstance _ ty = throwError . errorMessage $ InvalidInstanceHead ty
161161-- Check that type synonyms are fully-applied in a type
162162--
163163checkTypeSynonyms
164− :: (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
164+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
165165 => Type
166166 -> m ()
167167checkTypeSynonyms = void . replaceAllTypeSynonyms
@@ -181,7 +181,7 @@ checkTypeSynonyms = void . replaceAllTypeSynonyms
181181--
182182typeCheckAll
183183 :: forall m
184− . (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
184+ . (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
185185 => ModuleName
186186 -> [DeclarationRef]
187187 -> [Declaration]
@@ -343,7 +343,7 @@ typeCheckAll moduleName _ ds = traverse go ds <* traverse_ checkFixities ds
343343--
344344typeCheckModule
345345 :: forall m
346− . (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
346+ . (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
347347 => Module
348348 -> m Module
349349typeCheckModule (Module _ _ _ _ Nothing) = internalError "exports should have been elaborated"
src/Language/PureScript/TypeChecker/Entailment.hs+81−32
@@ -4,7 +4,7 @@
44-- |
55-- Type class entailment
66--
7−module Language.PureScript.TypeChecker.Entailment (entails) where
7+module Language.PureScript.TypeChecker.Entailment (Context, replaceTypeClassDictionaries) where
88
99import Prelude ()
1010import Prelude.Compat
@@ -16,8 +16,9 @@ import qualified Data.Map as M
1616
1717import Control.Arrow (Arrow(..))
1818import Control.Monad.State
19+import Control.Monad.Writer
1920import Control.Monad.Error.Class (MonadError(..))
20−import Control.Monad.Writer.Class (MonadWriter(..))
21+import Control.Monad.Supply.Class (MonadSupply(..))
2122
2223import Language.PureScript.Crash
2324import Language.PureScript.AST
@@ -28,22 +29,47 @@ import Language.PureScript.TypeClassDictionaries
2829import Language.PureScript.Types
2930import qualified Language.PureScript.Constants as C
3031
32+-- | The 'Context' tracks those constraints which can be satisfied.
33+type Context = M.Map (Maybe ModuleName)
34+ (M.Map (Qualified (ProperName 'ClassName))
35+ (M.Map (Qualified Ident)
36+ TypeClassDictionaryInScope))
37+
38+-- | Merge two type class contexts
39+combineContexts :: Context -> Context -> Context
40+combineContexts = M.unionWith (M.unionWith M.union)
41+
42+-- | Replace type class dictionary placeholders with inferred type class dictionaries
43+replaceTypeClassDictionaries
44+ :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadSupply m)
45+ => Bool
46+ -> ModuleName
47+ -> Expr
48+ -> m (Expr, [(Ident, Constraint)])
49+replaceTypeClassDictionaries shouldGeneralize mn =
50+ let (_, f, _) = everywhereOnValuesTopDownM return (WriterT . go) return
51+ in flip evalStateT M.empty . runWriterT . f
52+ where
53+ go (TypeClassDictionary constraint dicts) = entails shouldGeneralize mn dicts constraint
54+ go other = return (other, [])
55+
3156-- |
3257-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
3358-- return a type class dictionary reference.
3459--
3560entails
3661 :: forall m
37− . (Functor m, Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
38− => ModuleName
39− -> M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope))
62+ . (MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadSupply m)
63+ => Bool
64+ -> ModuleName
65+ -> Context
4066 -> Constraint
41− -> m Expr
42−entails moduleName context = solve
67+ -> StateT Context m (Expr, [(Ident, Constraint)])
68+entails shouldGeneralize moduleName context = solve
4369 where
44− forClassName :: Qualified (ProperName 'ClassName) -> [Type] -> [TypeClassDictionaryInScope]
45− forClassName cn@(Qualified (Just mn) _) tys = concatMap (findDicts cn) (Nothing : Just mn : map Just (mapMaybe ctorModules tys))
46− forClassName _ _ = internalError "forClassName: expected qualified class name"
70+ forClassName :: Context -> Qualified (ProperName 'ClassName) -> [Type] -> [TypeClassDictionaryInScope]
71+ forClassName ctx cn@(Qualified (Just mn) _) tys = concatMap (findDicts ctx cn) (Nothing : Just mn : map Just (mapMaybe ctorModules tys))
72+ forClassName _ _ _ = internalError "forClassName: expected qualified class name"
4773
4874 ctorModules :: Type -> Maybe ModuleName
4975 ctorModules (TypeConstructor (Qualified (Just mn) _)) = Just mn
@@ -51,37 +77,58 @@ entails moduleName context = solve
5177 ctorModules (TypeApp ty _) = ctorModules ty
5278 ctorModules _ = Nothing
5379
54− findDicts :: Qualified (ProperName 'ClassName) -> Maybe ModuleName -> [TypeClassDictionaryInScope]
55− findDicts cn = maybe [] M.elems . (>>= M.lookup cn) . flip M.lookup context
80+ findDicts :: Context -> Qualified (ProperName 'ClassName) -> Maybe ModuleName -> [TypeClassDictionaryInScope]
81+ findDicts ctx cn = maybe [] M.elems . (>>= M.lookup cn) . flip M.lookup ctx
5682
57− solve :: Constraint -> m Expr
83+ solve :: Constraint -> StateT Context m (Expr, [(Ident, Constraint)])
5884 solve (className, tys) = do
59− dict <- go 0 className tys
60− return $ dictionaryValueToValue dict
85+ (dict, unsolved) <- go 0 className tys
86+ return (dictionaryValueToValue dict, unsolved)
6187 where
62− go :: Int -> Qualified (ProperName 'ClassName) -> [Type] -> m DictionaryValue
88+ go :: Int -> Qualified (ProperName 'ClassName) -> [Type] -> StateT Context m (DictionaryValue, [(Ident, Constraint)])
6389 go work className' tys' | work > 1000 = throwError . errorMessage $ PossiblyInfiniteInstance className' tys'
6490 go work className' tys' = do
91+ -- Get the inferred constraint context so far, and merge it with the global context
92+ inferred <- get
6593 let instances = do
66− tcd <- forClassName className' tys'
94+ tcd <- forClassName (combineContexts context inferred) className' tys'
6795 -- Make sure the type unifies with the type in the type instance definition
6896 subst <- maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName) tys' (tcdInstanceTypes tcd)
6997 return (subst, tcd)
70− (subst, tcd) <- unique instances
71− -- Solve any necessary subgoals
72− args <- solveSubgoals subst (tcdDependencies tcd)
73− return $ foldr (\(superclassName, index) dict -> SubclassDictionaryValue dict superclassName index)
74− (mkDictionary (tcdName tcd) args)
75− (tcdPath tcd)
98+ solution <- lift $ unique instances
99+ case solution of
100+ Left (subst, tcd) -> do
101+ -- Solve any necessary subgoals
102+ (args, unsolved) <- solveSubgoals subst (tcdDependencies tcd)
103+ let match = foldr (\(superclassName, index) dict -> SubclassDictionaryValue dict superclassName index)
104+ (mkDictionary (tcdName tcd) args)
105+ (tcdPath tcd)
106+ return (match, unsolved)
107+ Right unsolved@(unsolvedClassName@(Qualified _ pn), unsolvedTys) -> do
108+ -- Generate a fresh name for the unsolved constraint's new dictionary
109+ ident <- freshIdent ("dict" ++ runProperName pn)
110+ let qident = Qualified Nothing ident
111+ -- Store the new dictionary in the Context so that we can solve this goal in
112+ -- future.
113+ let newDict = TypeClassDictionaryInScope qident [] unsolvedClassName unsolvedTys Nothing
114+ newContext = M.singleton Nothing (M.singleton unsolvedClassName (M.singleton qident newDict))
115+ modify (combineContexts newContext)
116+ return (LocalDictionaryValue qident, [(ident, unsolved)])
76117 where
77118
78− unique :: [(a, TypeClassDictionaryInScope)] -> m (a, TypeClassDictionaryInScope)
79− unique [] = throwError . errorMessage $ NoInstanceFound className' tys'
80− unique [a] = return a
119+ unique :: [(a, TypeClassDictionaryInScope)] -> m (Either (a, TypeClassDictionaryInScope) Constraint)
120+ unique [] | shouldGeneralize && all canBeGeneralized tys' = return $ Right (className, tys)
121+ | otherwise = throwError . errorMessage $ NoInstanceFound className' tys'
122+ unique [a] = return $ Left a
81123 unique tcds | pairwise overlapping (map snd tcds) = do
82124 tell . errorMessage $ OverlappingInstances className' tys' (map (tcdName . snd) tcds)
83− return (head tcds)
84− | otherwise = return (minimumBy (compare `on` length . tcdPath . snd) tcds)
125+ return $ Left (head tcds)
126+ | otherwise = return $ Left (minimumBy (compare `on` length . tcdPath . snd) tcds)
127+
128+ canBeGeneralized :: Type -> Bool
129+ canBeGeneralized TUnknown{} = True
130+ canBeGeneralized Skolem{} = True
131+ canBeGeneralized _ = False
85132
86133 -- |
87134 -- Check if two dictionaries are overlapping
@@ -98,11 +145,12 @@ entails moduleName context = solve
98145 -- Create dictionaries for subgoals which still need to be solved by calling go recursively
99146 -- E.g. the goal (Show a, Show b) => Show (Either a b) can be satisfied if the current type
100147 -- unifies with Either a b, and we can satisfy the subgoals Show a and Show b recursively.
101− solveSubgoals :: [(String, Type)] -> Maybe [Constraint] -> m (Maybe [DictionaryValue])
102− solveSubgoals _ Nothing = return Nothing
148+ solveSubgoals :: [(String, Type)] -> Maybe [Constraint] -> StateT Context m (Maybe [DictionaryValue], [(Ident, Constraint)])
149+ solveSubgoals _ Nothing = return (Nothing, [])
103150 solveSubgoals subst (Just subgoals) = do
104− dict <- traverse (uncurry (go (work + 1)) . second (map (replaceAllTypeVars subst))) subgoals
105− return $ Just dict
151+ zipped <- traverse (uncurry (go (work + 1)) . second (map (replaceAllTypeVars subst))) subgoals
152+ let (dicts, unsolved) = unzip zipped
153+ return (Just dicts, concat unsolved)
106154
107155 -- Make a dictionary from subgoal dictionaries by applying the correct function
108156 mkDictionary :: Qualified Ident -> Maybe [DictionaryValue] -> DictionaryValue
@@ -134,6 +182,7 @@ entails moduleName context = solve
134182-- and return a substitution from type variables to types which makes the type heads unify.
135183--
136184typeHeadsAreEqual :: ModuleName -> Type -> Type -> Maybe [(String, Type)]
185+typeHeadsAreEqual _ (TUnknown u1) (TUnknown u2) | u1 == u2 = Just []
137186typeHeadsAreEqual _ (Skolem _ s1 _ _) (Skolem _ s2 _ _) | s1 == s2 = Just []
138187typeHeadsAreEqual _ t (TypeVar v) = Just [(v, t)]
139188typeHeadsAreEqual _ (TypeConstructor c1) (TypeConstructor c2) | c1 == c2 = Just []
src/Language/PureScript/TypeChecker/Kinds.hs+11−11
@@ -43,7 +43,7 @@ freshKind = do
4343
4444-- | Update the substitution to solve a kind constraint
4545solveKind
46− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m)
46+ :: (MonadError MultipleErrors m, MonadState CheckState m)
4747 => Int
4848 -> Kind
4949 -> m ()
@@ -68,7 +68,7 @@ substituteKind sub = everywhereOnKinds go
6868
6969-- | Make sure that an unknown does not occur in a kind
7070occursCheck
71− :: (Functor m, Applicative m, MonadError MultipleErrors m)
71+ :: (MonadError MultipleErrors m)
7272 => Int
7373 -> Kind
7474 -> m ()
@@ -80,7 +80,7 @@ occursCheck u k = void $ everywhereOnKindsM go k
8080
8181-- | Unify two kinds
8282unifyKinds
83− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m)
83+ :: (MonadError MultipleErrors m, MonadState CheckState m)
8484 => Kind
8585 -> Kind
8686 -> m ()
@@ -101,14 +101,14 @@ unifyKinds k1 k2 = do
101101
102102-- | Infer the kind of a single type
103103kindOf
104− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m)
104+ :: (MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m)
105105 => Type
106106 -> m Kind
107107kindOf ty = fst <$> kindOfWithScopedVars ty
108108
109109-- | Infer the kind of a single type, returning the kinds of any scoped type variables
110110kindOfWithScopedVars ::
111− (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m) =>
111+ (MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m) =>
112112 Type ->
113113 m (Kind, [(String, Kind)])
114114kindOfWithScopedVars ty =
@@ -121,7 +121,7 @@ kindOfWithScopedVars ty =
121121
122122-- | Infer the kind of a type constructor with a collection of arguments and a collection of associated data constructors
123123kindsOf
124− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m)
124+ :: (MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m)
125125 => Bool
126126 -> ModuleName
127127 -> ProperName 'TypeName
@@ -139,7 +139,7 @@ kindsOf isData moduleName name args ts = fmap tidyUp . liftUnify $ do
139139 tidyUp (k, sub) = starIfUnknown $ substituteKind sub k
140140
141141freshKindVar
142− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m)
142+ :: (MonadError MultipleErrors m, MonadState CheckState m)
143143 => (String, Maybe Kind)
144144 -> Kind
145145 -> m (ProperName 'TypeName, Kind)
@@ -150,7 +150,7 @@ freshKindVar (arg, Just kind') kind = do
150150
151151-- | Simultaneously infer the kinds of several mutually recursive type constructors
152152kindsOfAll
153− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m)
153+ :: (MonadError MultipleErrors m, MonadState CheckState m, MonadWriter MultipleErrors m)
154154 => ModuleName
155155 -> [(ProperName 'TypeName, [(String, Maybe Kind)], Type)]
156156 -> [(ProperName 'TypeName, [(String, Maybe Kind)], [Type])]
@@ -178,7 +178,7 @@ kindsOfAll moduleName syns tys = fmap tidyUp . liftUnify $ do
178178
179179-- | Solve the set of kind constraints associated with the data constructors for a type constructor
180180solveTypes
181− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m)
181+ :: (MonadError MultipleErrors m, MonadState CheckState m)
182182 => Bool
183183 -> [Type]
184184 -> [Kind]
@@ -202,14 +202,14 @@ starIfUnknown k = k
202202
203203-- | Infer a kind for a type
204204infer
205− :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m)
205+ :: (MonadError MultipleErrors m, MonadState CheckState m)
206206 => Type
207207 -> m (Kind, [(String, Kind)])
208208infer ty = rethrow (addHint (ErrorCheckingKind ty)) $ infer' ty
209209
210210infer'
211211 :: forall m
212− . (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m)
212+ . (MonadError MultipleErrors m, MonadState CheckState m)
213213 => Type
214214 -> m (Kind, [(String, Kind)])
215215infer' (ForAll ident ty _) = do
src/Language/PureScript/TypeChecker/Monad.hs+15−15
@@ -84,7 +84,7 @@ bindTypes newNames action = do
8484
8585-- | Temporarily bind a collection of names to types
8686withScopedTypeVars
87− :: (Functor m, Applicative m, MonadState CheckState m, MonadWriter MultipleErrors m)
87+ :: (MonadState CheckState m, MonadWriter MultipleErrors m)
8888 => ModuleName
8989 -> [(String, Kind)]
9090 -> m a
@@ -112,20 +112,20 @@ withTypeClassDictionaries entries action = do
112112
113113-- | Get the currently available map of type class dictionaries
114114getTypeClassDictionaries
115− :: (Functor m, MonadState CheckState m)
115+ :: (MonadState CheckState m)
116116 => m (M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope)))
117117getTypeClassDictionaries = typeClassDictionaries . checkEnv <$> get
118118
119119-- | Lookup type class dictionaries in a module.
120120lookupTypeClassDictionaries
121− :: (Functor m, MonadState CheckState m)
121+ :: (MonadState CheckState m)
122122 => Maybe ModuleName
123123 -> m (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope))
124124lookupTypeClassDictionaries mn = fromMaybe M.empty . M.lookup mn . typeClassDictionaries . checkEnv <$> get
125125
126126-- | Temporarily bind a collection of names to local variables
127127bindLocalVariables
128− :: (Functor m, MonadState CheckState m)
128+ :: (MonadState CheckState m)
129129 => ModuleName
130130 -> [(Ident, Type, NameVisibility)]
131131 -> m a
@@ -135,7 +135,7 @@ bindLocalVariables moduleName bindings =
135135
136136-- | Temporarily bind a collection of names to local type variables
137137bindLocalTypeVariables
138− :: (Functor m, MonadState CheckState m)
138+ :: (MonadState CheckState m)
139139 => ModuleName
140140 -> [(ProperName 'TypeName, Kind)]
141141 -> m a
@@ -144,15 +144,15 @@ bindLocalTypeVariables moduleName bindings =
144144 bindTypes (M.fromList $ flip map bindings $ \(pn, kind) -> (Qualified (Just moduleName) pn, (kind, LocalTypeVariable)))
145145
146146-- | Update the visibility of all names to Defined
147−makeBindingGroupVisible :: (Functor m, MonadState CheckState m) => m ()
147+makeBindingGroupVisible :: (MonadState CheckState m) => m ()
148148makeBindingGroupVisible = modifyEnv $ \e -> e { names = M.map (\(ty, nk, _) -> (ty, nk, Defined)) (names e) }
149149
150150-- | Update the visibility of all names to Defined in the scope of the provided action
151−withBindingGroupVisible :: (Functor m, MonadState CheckState m) => m a -> m a
151+withBindingGroupVisible :: (MonadState CheckState m) => m a -> m a
152152withBindingGroupVisible action = preservingNames $ makeBindingGroupVisible >> action
153153
154154-- | Perform an action while preserving the names from the @Environment@.
155−preservingNames :: (Functor m, MonadState CheckState m) => m a -> m a
155+preservingNames :: (MonadState CheckState m) => m a -> m a
156156preservingNames action = do
157157 orig <- gets (names . checkEnv)
158158 a <- action
@@ -161,7 +161,7 @@ preservingNames action = do
161161
162162-- | Lookup the type of a value by name in the @Environment@
163163lookupVariable
164− :: (e ~ MultipleErrors, Functor m, MonadState CheckState m, MonadError e m)
164+ :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
165165 => ModuleName
166166 -> Qualified Ident
167167 -> m Type
@@ -173,7 +173,7 @@ lookupVariable currentModule (Qualified moduleName var) = do
173173
174174-- | Lookup the visibility of a value by name in the @Environment@
175175getVisibility
176− :: (e ~ MultipleErrors, Functor m, MonadState CheckState m, MonadError e m)
176+ :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
177177 => ModuleName
178178 -> Qualified Ident
179179 -> m NameVisibility
@@ -185,7 +185,7 @@ getVisibility currentModule (Qualified moduleName var) = do
185185
186186-- | Assert that a name is visible
187187checkVisibility
188− :: (e ~ MultipleErrors, Functor m, MonadState CheckState m, MonadError e m)
188+ :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
189189 => ModuleName
190190 -> Qualified Ident
191191 -> m ()
@@ -197,7 +197,7 @@ checkVisibility currentModule name@(Qualified _ var) = do
197197
198198-- | Lookup the kind of a type by name in the @Environment@
199199lookupTypeVariable
200− :: (e ~ MultipleErrors, Functor m, MonadState CheckState m, MonadError e m)
200+ :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
201201 => ModuleName
202202 -> Qualified (ProperName 'TypeName)
203203 -> m Kind
@@ -208,7 +208,7 @@ lookupTypeVariable currentModule (Qualified moduleName name) = do
208208 Just (k, _) -> return k
209209
210210-- | Get the current @Environment@
211−getEnv :: (Functor m, MonadState CheckState m) => m Environment
211+getEnv :: (MonadState CheckState m) => m Environment
212212getEnv = checkEnv <$> get
213213
214214-- | Update the @Environment@
@@ -234,14 +234,14 @@ guardWith e False = throwError e
234234
235235-- | Run a computation in the substitution monad, generating a return value and the final substitution.
236236liftUnify ::
237− (Functor m, MonadState CheckState m, MonadWriter MultipleErrors m, MonadError MultipleErrors m) =>
237+ (MonadState CheckState m, MonadWriter MultipleErrors m, MonadError MultipleErrors m) =>
238238 m a ->
239239 m (a, Substitution)
240240liftUnify = liftUnifyWarnings (const id)
241241
242242-- | Run a computation in the substitution monad, generating a return value, the final substitution and updating warnings values.
243243liftUnifyWarnings ::
244− (Functor m, MonadState CheckState m, MonadWriter MultipleErrors m, MonadError MultipleErrors m) =>
244+ (MonadState CheckState m, MonadWriter MultipleErrors m, MonadError MultipleErrors m) =>
245245 (Substitution -> ErrorMessage -> ErrorMessage) ->
246246 m a ->
247247 m (a, Substitution)
src/Language/PureScript/TypeChecker/Rows.hs+1−1
@@ -36,7 +36,7 @@ import Language.PureScript.TypeChecker.Monad
3636import Language.PureScript.Types
3737
3838-- | Ensure rows do not contain duplicate labels
39−checkDuplicateLabels :: forall m. (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m) => Expr -> m ()
39+checkDuplicateLabels :: forall m. (MonadError MultipleErrors m, MonadState CheckState m) => Expr -> m ()
4040checkDuplicateLabels =
4141 let (_, f, _) = everywhereOnValuesM def go def
4242 in void . f
src/Language/PureScript/TypeChecker/Skolems.hs+1−1
@@ -53,7 +53,7 @@ newSkolemConstant = do
5353-- |
5454-- Introduce skolem scope at every occurence of a ForAll
5555--
56−introduceSkolemScope :: (Functor m, Applicative m, MonadState CheckState m) => Type -> m Type
56+introduceSkolemScope :: (MonadState CheckState m) => Type -> m Type
5757introduceSkolemScope = everywhereOnTypesM go
5858 where
5959 go (ForAll ident ty Nothing) = ForAll ident ty <$> (Just <$> newSkolemScope)
src/Language/PureScript/TypeChecker/Subsumption.hs+2−2
@@ -39,11 +39,11 @@ import Language.PureScript.TypeChecker.Unify
3939import Language.PureScript.Types
4040
4141-- | Check that one type subsumes another, rethrowing errors to provide a better error message
42−subsumes :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m) => Maybe Expr -> Type -> Type -> m (Maybe Expr)
42+subsumes :: (MonadError MultipleErrors m, MonadState CheckState m) => Maybe Expr -> Type -> Type -> m (Maybe Expr)
4343subsumes val ty1 ty2 = rethrow (addHint (ErrorInSubsumption ty1 ty2)) $ subsumes' val ty1 ty2
4444
4545-- | Check tahat one type subsumes another
46−subsumes' :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m) =>
46+subsumes' :: (MonadError MultipleErrors m, MonadState CheckState m) =>
4747 Maybe Expr ->
4848 Type ->
4949 Type ->
src/Language/PureScript/TypeChecker/Synonyms.hs+1−1
@@ -57,7 +57,7 @@ replaceAllTypeSynonyms' env = everywhereOnTypesTopDownM try
5757 go c args (TypeApp f arg) = go (c + 1) (arg : args) f
5858 go _ _ _ = return Nothing
5959
60−replaceAllTypeSynonyms :: (e ~ MultipleErrors, Functor m, Monad m, MonadState CheckState m, MonadError e m) => Type -> m Type
60+replaceAllTypeSynonyms :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m) => Type -> m Type
6161replaceAllTypeSynonyms d = do
6262 env <- getEnv
6363 either throwError return $ replaceAllTypeSynonyms' env d
src/Language/PureScript/TypeChecker/Types.hs+72−90
@@ -2,6 +2,7 @@
22{-# LANGUAGE ScopedTypeVariables #-}
33{-# LANGUAGE MultiParamTypeClasses #-}
44{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TupleSections #-}
56
67-- |
78-- This module implements the type checker
@@ -61,7 +62,7 @@ import Language.PureScript.Types
6162-- | Infer the types of multiple mutually-recursive values, and return elaborated values including
6263-- type class dictionaries and type annotations.
6364typesOf ::
64− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
65+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
6566 ModuleName ->
6667 [(Ident, Expr)] ->
6768 m [(Ident, (Expr, Type))]
@@ -69,23 +70,38 @@ typesOf moduleName vals = do
6970 tys <- fmap tidyUp . liftUnifyWarnings replace $ do
7071 (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup moduleName vals
7172 ds1 <- parU typed $ \e -> checkTypedBindingGroupElement moduleName e dict
72− ds2 <- forM untyped $ \e -> typeForBindingGroupElement True e dict untypedDict
73− return $ ds1 ++ ds2
73+ ds2 <- forM untyped $ \e -> typeForBindingGroupElement e dict untypedDict
74+ return (map (\x -> (False, x)) ds1 ++ map (\x -> (True, x)) ds2)
7475
75− forM tys $ \(ident, (val, ty)) -> do
76+ forM tys $ \(shouldGeneralize, (ident, (val, ty))) -> do
7677 -- Replace type class dictionary placeholders with actual dictionaries
77− val' <- replaceTypeClassDictionaries moduleName val
78+ (val', unsolved) <- replaceTypeClassDictionaries shouldGeneralize moduleName val
79+ let unsolvedTypeVars = nub $ unknownsInType ty
80+ -- Generalize and constrain the type
81+ let generalized = generalize unsolved ty
82+ -- Make sure any unsolved type constraints only use type variables which appear
83+ -- unknown in the inferred type.
84+ when shouldGeneralize $ do
85+ tell . errorMessage $ MissingTypeDeclaration ident generalized
86+ forM_ unsolved $ \(_, (className, classTys)) -> do
87+ let constraintTypeVars = nub $ foldMap unknownsInType classTys
88+ when (any (`notElem` unsolvedTypeVars) constraintTypeVars) $
89+ throwError . errorMessage $ NoInstanceFound className classTys
7890 -- Check skolem variables did not escape their scope
7991 skolemEscapeCheck val'
8092 -- Check rows do not contain duplicate labels
8193 checkDuplicateLabels val'
82− return (ident, (val', varIfUnknown ty))
94+ return (ident, (foldr (Abs . Left . fst) val' unsolved, generalized))
8395 where
96+ -- | Generalize type vars using forall and add inferred constraints
97+ generalize unsolved = varIfUnknown . constrain unsolved
98+ -- | Add any unsolved constraints
99+ constrain [] = id
100+ constrain cs = ConstrainedType (map snd cs)
84101 -- Apply the substitution that was returned from runUnify to both types and (type-annotated) values
85− tidyUp (ts, sub) = map (\(i, (val, ty)) -> (i, (overTypes (substituteType sub) val, substituteType sub ty))) ts
102+ tidyUp (ts, sub) = map (\(b, (i, (val, ty))) -> (b, (i, (overTypes (substituteType sub) val, substituteType sub ty)))) ts
86103 -- Replace all the wildcards types with their inferred types
87104 replace sub (ErrorMessage hints (WildcardInferredType ty)) = ErrorMessage hints . WildcardInferredType $ substituteType sub ty
88− replace sub (ErrorMessage hints (MissingTypeDeclaration name ty)) = ErrorMessage hints $ MissingTypeDeclaration name (varIfUnknown (substituteType sub ty))
89105 replace _ em = em
90106
91107type TypeData = M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
@@ -93,7 +109,7 @@ type TypeData = M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
93109type UntypedData = [(Ident, Type)]
94110
95111typeDictionaryForBindingGroup ::
96− (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
112+ (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
97113 ModuleName ->
98114 [(Ident, Expr)] ->
99115 m ([(Ident, Expr)], [(Ident, (Expr, Type, Bool))], TypeData, UntypedData)
@@ -118,7 +134,7 @@ typeDictionaryForBindingGroup moduleName vals = do
118134 return (untyped, typed, dict, untypedDict)
119135
120136checkTypedBindingGroupElement ::
121− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
137+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
122138 ModuleName ->
123139 (Ident, (Expr, Type, Bool)) ->
124140 TypeData ->
@@ -137,17 +153,15 @@ checkTypedBindingGroupElement mn (ident, (val', ty, checkType)) dict = do
137153 return (ident, (val'', ty''))
138154
139155typeForBindingGroupElement ::
140− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
141− Bool ->
156+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
142157 (Ident, Expr) ->
143158 TypeData ->
144159 UntypedData ->
145160 m (Ident, (Expr, Type))
146−typeForBindingGroupElement warn (ident, val) dict untypedDict = do
161+typeForBindingGroupElement (ident, val) dict untypedDict = do
147162 -- Infer the type with the new names in scope
148163 TypedValue _ val' ty <- bindNames dict $ infer val
149164 unifyTypes ty $ fromMaybe (internalError "name not found in dictionary") (lookup ident untypedDict)
150− when warn . tell . errorMessage $ MissingTypeDeclaration ident ty
151165 return (ident, (TypedValue True val' ty, ty))
152166
153167-- | Check if a value contains a type annotation
@@ -165,23 +179,10 @@ overTypes f = let (_, f', _) = everywhereOnValues id g id in f'
165179 g (TypedValue checkTy val t) = TypedValue checkTy val (f t)
166180 g (TypeClassDictionary (nm, tys) sco) = TypeClassDictionary (nm, map f tys) sco
167181 g other = other
168−
169−-- | Replace type class dictionary placeholders with inferred type class dictionaries
170−replaceTypeClassDictionaries ::
171− (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
172− ModuleName ->
173− Expr ->
174− m Expr
175−replaceTypeClassDictionaries mn =
176− let (_, f, _) = everywhereOnValuesTopDownM return go return
177− in f
178− where
179− go (TypeClassDictionary constraint dicts) = entails mn dicts constraint
180− go other = return other
181−
182+
182183-- | Check the kind of a type, failing if it is not of kind *.
183184checkTypeKind ::
184− (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m) =>
185+ (MonadState CheckState m, MonadError MultipleErrors m) =>
185186 Type ->
186187 Kind ->
187188 m ()
@@ -193,7 +194,7 @@ checkTypeKind ty kind = guardWith (errorMessage (ExpectedType ty kind)) $ kind =
193194-- This is necessary during type checking to avoid unifying a polymorphic type with a
194195-- unification variable.
195196instantiatePolyTypeWithUnknowns ::
196− (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m) =>
197+ (MonadState CheckState m, MonadError MultipleErrors m) =>
197198 Expr ->
198199 Type ->
199200 m (Expr, Type)
@@ -207,32 +208,32 @@ instantiatePolyTypeWithUnknowns val ty = return (val, ty)
207208
208209-- | Infer a type for a value, rethrowing any error to provide a more useful error message
209210infer ::
210− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
211+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
211212 Expr ->
212213 m Expr
213214infer val = rethrow (addHint (ErrorInferringType val)) $ infer' val
214215
215216-- | Infer a type for a value
216217infer' ::
217− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
218+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
218219 Expr ->
219220 m Expr
220−infer' v@(NumericLiteral (Left _)) = return $ TypedValue True v tyInt
221−infer' v@(NumericLiteral (Right _)) = return $ TypedValue True v tyNumber
222−infer' v@(StringLiteral _) = return $ TypedValue True v tyString
223−infer' v@(CharLiteral _) = return $ TypedValue True v tyChar
224−infer' v@(BooleanLiteral _) = return $ TypedValue True v tyBoolean
225−infer' (ArrayLiteral vals) = do
221+infer' v@(Literal (NumericLiteral (Left _))) = return $ TypedValue True v tyInt
222+infer' v@(Literal (NumericLiteral (Right _))) = return $ TypedValue True v tyNumber
223+infer' v@(Literal (StringLiteral _)) = return $ TypedValue True v tyString
224+infer' v@(Literal (CharLiteral _)) = return $ TypedValue True v tyChar
225+infer' v@(Literal (BooleanLiteral _)) = return $ TypedValue True v tyBoolean
226+infer' (Literal (ArrayLiteral vals)) = do
226227 ts <- traverse infer vals
227228 els <- freshType
228229 forM_ ts $ \(TypedValue _ _ t) -> unifyTypes els t
229− return $ TypedValue True (ArrayLiteral ts) (TypeApp tyArray els)
230−infer' (ObjectLiteral ps) = do
230+ return $ TypedValue True (Literal (ArrayLiteral ts)) (TypeApp tyArray els)
231+infer' (Literal (ObjectLiteral ps)) = do
231232 ensureNoDuplicateProperties ps
232233 ts <- traverse (infer . snd) ps
233234 let fields = zipWith (\name (TypedValue _ _ t) -> (name, t)) (map fst ps) ts
234235 ty = TypeApp tyObject $ rowFromList (fields, REmpty)
235− return $ TypedValue True (ObjectLiteral (zip (map fst ps) ts)) ty
236+ return $ TypedValue True (Literal (ObjectLiteral (zip (map fst ps) ts))) ty
236237infer' (ObjectUpdate o ps) = do
237238 ensureNoDuplicateProperties ps
238239 row <- freshType
@@ -280,10 +281,10 @@ infer' (Case vals binders) = do
280281 return $ TypedValue True (Case vals' binders') ret
281282infer' (IfThenElse cond th el) = do
282283 cond' <- check cond tyBoolean
283− v2@(TypedValue _ _ t2) <- infer th
284− v3@(TypedValue _ _ t3) <- infer el
285− (v2', v3', t) <- meet v2 v3 t2 t3
286− return $ TypedValue True (IfThenElse cond' v2' v3') t
284+ th'@(TypedValue _ _ thTy) <- infer th
285+ el'@(TypedValue _ _ elTy) <- infer el
286+ unifyTypes thTy elTy
287+ return $ TypedValue True (IfThenElse cond' th' el') thTy
287288infer' (Let ds val) = do
288289 (ds', val'@(TypedValue _ _ valTy)) <- inferLetBinding [] ds val infer
289290 return $ TypedValue True (Let ds' val') valTy
@@ -303,7 +304,7 @@ infer' (PositionedValue pos c val) = warnAndRethrowWithPosition pos $ do
303304infer' _ = internalError "Invalid argument to infer"
304305
305306inferLetBinding ::
306− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
307+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
307308 [Declaration] ->
308309 [Declaration] ->
309310 Expr ->
@@ -329,7 +330,7 @@ inferLetBinding seen (BindingGroupDeclaration ds : rest) ret j = do
329330 Just moduleName <- checkCurrentModule <$> get
330331 (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup moduleName (map (\(i, _, v) -> (i, v)) ds)
331332 ds1' <- parU typed $ \e -> checkTypedBindingGroupElement moduleName e dict
332− ds2' <- forM untyped $ \e -> typeForBindingGroupElement False e dict untypedDict
333+ ds2' <- forM untyped $ \e -> typeForBindingGroupElement e dict untypedDict
333334 let ds' = [(ident, Private, val') | (ident, (val', _)) <- ds1' ++ ds2']
334335 bindNames dict $ do
335336 makeBindingGroupVisible
@@ -341,16 +342,16 @@ inferLetBinding _ _ _ _ = internalError "Invalid argument to inferLetBinding"
341342
342343-- | Infer the types of variables brought into scope by a binder
343344inferBinder :: forall m.
344− (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
345+ (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
345346 Type ->
346347 Binder ->
347348 m (M.Map Ident Type)
348349inferBinder _ NullBinder = return M.empty
349−inferBinder val (StringBinder _) = unifyTypes val tyString >> return M.empty
350−inferBinder val (CharBinder _) = unifyTypes val tyChar >> return M.empty
351−inferBinder val (NumberBinder (Left _)) = unifyTypes val tyInt >> return M.empty
352−inferBinder val (NumberBinder (Right _)) = unifyTypes val tyNumber >> return M.empty
353−inferBinder val (BooleanBinder _) = unifyTypes val tyBoolean >> return M.empty
350+inferBinder val (LiteralBinder (StringLiteral _)) = unifyTypes val tyString >> return M.empty
351+inferBinder val (LiteralBinder (CharLiteral _)) = unifyTypes val tyChar >> return M.empty
352+inferBinder val (LiteralBinder (NumericLiteral (Left _))) = unifyTypes val tyInt >> return M.empty
353+inferBinder val (LiteralBinder (NumericLiteral (Right _))) = unifyTypes val tyNumber >> return M.empty
354+inferBinder val (LiteralBinder (BooleanLiteral _)) = unifyTypes val tyBoolean >> return M.empty
354355inferBinder val (VarBinder name) = return $ M.singleton name val
355356inferBinder val (ConstructorBinder ctor binders) = do
356357 env <- getEnv
@@ -369,7 +370,7 @@ inferBinder val (ConstructorBinder ctor binders) = do
369370 where
370371 go args (TypeApp (TypeApp fn arg) ret) | fn == tyFunction = go (arg : args) ret
371372 go args ret = (args, ret)
372−inferBinder val (ObjectBinder props) = do
373+inferBinder val (LiteralBinder (ObjectLiteral props)) = do
373374 row <- freshType
374375 rest <- freshType
375376 m1 <- inferRowProperties row rest props
@@ -383,7 +384,7 @@ inferBinder val (ObjectBinder props) = do
383384 m1 <- inferBinder propTy binder
384385 m2 <- inferRowProperties nrow (RCons name propTy row) binders
385386 return $ m1 `M.union` m2
386−inferBinder val (ArrayBinder binders) = do
387+inferBinder val (LiteralBinder (ArrayLiteral binders)) = do
387388 el <- freshType
388389 m1 <- M.unions <$> traverse (inferBinder el) binders
389390 unifyTypes val (TypeApp tyArray el)
@@ -420,7 +421,7 @@ binderRequiresMonotype _ = True
420421
421422-- | Instantiate polytypes only when necessitated by a binder.
422423instantiateForBinders ::
423− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
424+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
424425 [Expr] ->
425426 [CaseAlternative] ->
426427 m ([Expr], [Type])
@@ -437,7 +438,7 @@ instantiateForBinders vals cas = unzip <$> zipWithM (\val inst -> do
437438-- Check the types of the return values in a set of binders in a case statement
438439--
439440checkBinders ::
440− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
441+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
441442 [Type] ->
442443 Type ->
443444 [CaseAlternative] ->
@@ -467,7 +468,7 @@ checkBinders nvals ret (CaseAlternative binders result : bs) = do
467468-- Check the type of a value, rethrowing errors to provide a better error message
468469--
469470check ::
470− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
471+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
471472 Expr ->
472473 Type ->
473474 m Expr
@@ -478,7 +479,7 @@ check val ty = rethrow (addHint (ErrorCheckingType val ty)) $ check' val ty
478479--
479480check'
480481 :: forall m
481− . (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
482+ . (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
482483 => Expr
483484 -> Type
484485 -> m Expr
@@ -524,19 +525,19 @@ check' val u@(TUnknown _) = do
524525 (val'', ty') <- instantiatePolyTypeWithUnknowns val' ty
525526 unifyTypes ty' u
526527 return $ TypedValue True val'' ty'
527−check' v@(NumericLiteral (Left _)) t | t == tyInt =
528+check' v@(Literal (NumericLiteral (Left _))) t | t == tyInt =
528529 return $ TypedValue True v t
529−check' v@(NumericLiteral (Right _)) t | t == tyNumber =
530+check' v@(Literal (NumericLiteral (Right _))) t | t == tyNumber =
530531 return $ TypedValue True v t
531−check' v@(StringLiteral _) t | t == tyString =
532+check' v@(Literal (StringLiteral _)) t | t == tyString =
532533 return $ TypedValue True v t
533−check' v@(CharLiteral _) t | t == tyChar =
534+check' v@(Literal (CharLiteral _)) t | t == tyChar =
534535 return $ TypedValue True v t
535−check' v@(BooleanLiteral _) t | t == tyBoolean =
536+check' v@(Literal (BooleanLiteral _)) t | t == tyBoolean =
536537 return $ TypedValue True v t
537−check' (ArrayLiteral vals) t@(TypeApp a ty) = do
538+check' (Literal (ArrayLiteral vals)) t@(TypeApp a ty) = do
538539 unifyTypes a tyArray
539− array <- ArrayLiteral <$> forM vals (`check` ty)
540+ array <- Literal . ArrayLiteral <$> forM vals (`check` ty)
540541 return $ TypedValue True array t
541542check' (Abs (Left arg) ret) ty@(TypeApp (TypeApp t argTy) retTy) = do
542543 unifyTypes t tyFunction
@@ -587,10 +588,10 @@ check' (IfThenElse cond th el) ty = do
587588 th' <- check th ty
588589 el' <- check el ty
589590 return $ TypedValue True (IfThenElse cond' th' el') ty
590−check' e@(ObjectLiteral ps) t@(TypeApp obj row) | obj == tyObject = do
591+check' e@(Literal (ObjectLiteral ps)) t@(TypeApp obj row) | obj == tyObject = do
591592 ensureNoDuplicateProperties ps
592593 ps' <- checkProperties e ps row False
593− return $ TypedValue True (ObjectLiteral ps') t
594+ return $ TypedValue True (Literal (ObjectLiteral ps')) t
594595check' (TypeClassDictionaryConstructorApp name ps) t = do
595596 ps' <- check' ps t
596597 return $ TypedValue True (TypeClassDictionaryConstructorApp name ps') t
@@ -641,7 +642,7 @@ check' val ty = do
641642-- The @lax@ parameter controls whether or not every record member has to be provided. For object updates, this is not the case.
642643--
643644checkProperties ::
644− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
645+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
645646 Expr ->
646647 [(String, Expr)] ->
647648 Type ->
@@ -673,7 +674,7 @@ checkProperties expr ps row lax = let (ts, r') = rowToList row in go ps ts r' wh
673674
674675-- | Check the type of a function application, rethrowing errors to provide a better error message
675676checkFunctionApplication ::
676− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
677+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
677678 Expr ->
678679 Type ->
679680 Expr ->
@@ -685,7 +686,7 @@ checkFunctionApplication fn fnTy arg ret = rethrow (addHint (ErrorInApplication
685686
686687-- | Check the type of a function application
687688checkFunctionApplication' ::
688− (Functor m, Applicative m, MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
689+ (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
689690 Expr ->
690691 Type ->
691692 Expr ->
@@ -720,25 +721,6 @@ checkFunctionApplication' fn fnTy dict@TypeClassDictionary{} _ =
720721 return (fnTy, App fn dict)
721722checkFunctionApplication' _ fnTy arg _ = throwError . errorMessage $ CannotApplyFunction fnTy arg
722723
723−-- | Compute the meet of two types, i.e. the most general type which both types subsume.
724−-- TODO: is this really needed?
725−meet ::
726− (Functor m, Applicative m, MonadState CheckState m, MonadError MultipleErrors m) =>
727− Expr ->
728− Expr ->
729− Type ->
730− Type ->
731− m (Expr, Expr, Type)
732−meet e1 e2 (ForAll ident t1 _) t2 = do
733− t1' <- replaceVarWithUnknown ident t1
734− meet e1 e2 t1' t2
735−meet e1 e2 t1 (ForAll ident t2 _) = do
736− t2' <- replaceVarWithUnknown ident t2
737− meet e1 e2 t1 t2'
738−meet e1 e2 t1 t2 = do
739− unifyTypes t1 t2
740− return (e1, e2, t1)
741−
742724-- |
743725-- Ensure a set of property names and value does not contain duplicate labels
744726--
src/Language/PureScript/TypeChecker/Unify.hs+6−5
@@ -23,6 +23,7 @@ module Language.PureScript.TypeChecker.Unify (
2323 freshType,
2424 solveType,
2525 substituteType,
26+ unknownsInType,
2627 unifyTypes,
2728 unifyRows,
2829 unifiesWith,
@@ -56,7 +57,7 @@ freshType = do
5657 return $ TUnknown t
5758
5859-- | Update the substitution to solve a type constraint
59−solveType :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m) => Int -> Type -> m ()
60+solveType :: (MonadError MultipleErrors m, MonadState CheckState m) => Int -> Type -> m ()
6061solveType u t = do
6162 occursCheck u t
6263 modify $ \cs -> cs { checkSubstitution =
@@ -77,7 +78,7 @@ substituteType sub = everywhereOnTypes go
7778 go other = other
7879
7980-- | Make sure that an unknown does not occur in a type
80−occursCheck :: (Functor m, Applicative m, MonadError MultipleErrors m) => Int -> Type -> m ()
81+occursCheck :: (MonadError MultipleErrors m) => Int -> Type -> m ()
8182occursCheck _ TUnknown{} = return ()
8283occursCheck u t = void $ everywhereOnTypesM go t
8384 where
@@ -93,7 +94,7 @@ unknownsInType t = everythingOnTypes (.) go t []
9394 go _ = id
9495
9596-- | Unify two types, updating the current substitution
96−unifyTypes :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m) => Type -> Type -> m ()
97+unifyTypes :: (MonadError MultipleErrors m, MonadState CheckState m) => Type -> Type -> m ()
9798unifyTypes t1 t2 = do
9899 sub <- gets checkSubstitution
99100 rethrow (addHint (ErrorUnifyingTypes t1 t2)) $ unifyTypes' (substituteType sub t1) (substituteType sub t2)
@@ -139,7 +140,7 @@ unifyTypes t1 t2 = do
139140-- trailing row unification variable, if appropriate, otherwise leftover labels result in a unification
140141-- error.
141142--
142−unifyRows :: forall m. (Functor m, Applicative m, MonadError MultipleErrors m, MonadState CheckState m) => Type -> Type -> m ()
143+unifyRows :: forall m. (MonadError MultipleErrors m, MonadState CheckState m) => Type -> Type -> m ()
143144unifyRows r1 r2 =
144145 let
145146 (s1, r1') = rowToList r1
@@ -205,7 +206,7 @@ replaceVarWithUnknown ident ty = do
205206-- |
206207-- Replace type wildcards with unknowns
207208--
208−replaceTypeWildcards :: (Functor m, Applicative m, MonadWriter MultipleErrors m, MonadState CheckState m) => Type -> m Type
209+replaceTypeWildcards :: (MonadWriter MultipleErrors m, MonadState CheckState m) => Type -> m Type
209210replaceTypeWildcards = everywhereOnTypesM replace
210211 where
211212 replace TypeWildcard = do
src/Language/PureScript/Types.hs+2−2
@@ -248,7 +248,7 @@ everywhereOnTypesTopDown f = go . f
248248 go (PrettyPrintForAll args t) = PrettyPrintForAll args (go (f t))
249249 go other = f other
250250
251−everywhereOnTypesM :: (Functor m, Applicative m, Monad m) => (Type -> m Type) -> Type -> m Type
251+everywhereOnTypesM :: Monad m => (Type -> m Type) -> Type -> m Type
252252everywhereOnTypesM f = go
253253 where
254254 go (TypeApp t1 t2) = (TypeApp <$> go t1 <*> go t2) >>= f
@@ -261,7 +261,7 @@ everywhereOnTypesM f = go
261261 go (PrettyPrintForAll args t) = (PrettyPrintForAll args <$> go t) >>= f
262262 go other = f other
263263
264−everywhereOnTypesTopDownM :: (Functor m, Applicative m, Monad m) => (Type -> m Type) -> Type -> m Type
264+everywhereOnTypesTopDownM :: Monad m => (Type -> m Type) -> Type -> m Type
265265everywhereOnTypesTopDownM f = go <=< f
266266 where
267267 go (TypeApp t1 t2) = TypeApp <$> (f t1 >>= go) <*> (f t2 >>= go)
stack-lts-2.yamldeleted−13
@@ -1,13 +0,0 @@
1−resolver: lts-2.22
2−packages:
3−- '.'
4−extra-deps:
5−- aeson-better-errors-0.8.0
6−- bower-json-0.7.0.0
7−- boxes-0.1.4
8−- pattern-arrows-0.0.2
9−- sourcemap-0.1.6
10−- fsnotify-0.2.1
11−- hfsevents-0.1.6
12−- pipes-http-1.0.2
13−flags: {}
stack-lts-3.yamldeleted−6
@@ -1,6 +0,0 @@
1−resolver: lts-3.22
2−packages:
3−- '.'
4−extra-deps:
5−- sourcemap-0.1.6
6−flags: {}