We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f8da0b9 commit 503cacaCopy full SHA for 503caca
examples/passing/EmptyDataDecls.purs
@@ -25,7 +25,6 @@ foreign import error
25
\ throw msg;\
26
\}" :: forall a. String -> a
27
28
-main = let (Array xs) = cons 1 $ cons 2 $ cons 3 nil
29
- in if xs == [1, 2, 3]
30
- then Debug.Trace.trace "Done"
31
- else error "Failed"
+main = case cons 1 $ cons 2 $ cons 3 nil of
+ Array [1, 2, 3] -> Debug.Trace.trace "Done"
+ _ -> error "Failed"
examples/passing/Let.purs
@@ -2,25 +2,50 @@ module Main where
2
3
import Prelude
4
import Control.Monad.Eff
5
+import Control.Monad.ST
6
-test1 x = let y = x + 1 in y
7
+test1 x = let
8
+ y :: Number
9
+ y = x + 1
10
+ in y
11
12
test2 x y =
13
let x' = x + 1 in
14
let y' = y + 1 in
15
x' + y'
16
-test3 x = let 1 = x in 2
-
-test4 = let f x y z = x + y + z in
17
+test3 = let f x y z = x + y + z in
18
f 1 2 3
19
-test5 = let f x [y, z] = x y z in
20
+test4 = let f x [y, z] = x y z in
21
f (+) [1, 2]
22
23
+test5 = let
24
+ f x | x > 0 = g (x / 2) + 1
+ f x = 0
+ g x = f (x - 1) + 1
+ in g 10
+
+test6 = runPure (runST (do
+ r <- newSTRef 0
+ (let
32
+ go [] = readSTRef r
33
+ go (n : ns) = do
34
+ modifySTRef r ((+) n)
35
+ go ns
36
+ in go [1, 2, 3, 4, 5])
37
+ ))
38
39
+test7 = let
40
+ f :: forall a. a -> a
41
+ f x = x
42
+ in if f true then f 1 else f 2
43
44
main = do
45
Debug.Trace.print (test1 1)
46
Debug.Trace.print (test2 1 2)
- Debug.Trace.print (test3 1)
47
+ Debug.Trace.print test3
48
Debug.Trace.print test4
49
Debug.Trace.print test5
50
+ Debug.Trace.print test6
51
+ Debug.Trace.print test7
examples/passing/MonadState.purs
@@ -14,8 +14,8 @@ runState s (State f) = f s
instance monadState :: Prelude.Monad (State s) where
return a = State $ \s -> Tuple s a
- (>>=) f g = State $ \s -> let (Tuple s1 a) = runState s f in
- runState s1 (g a)
+ (>>=) f g = State $ \s -> case runState s f of
+ Tuple s1 a -> runState s1 (g a)
instance monadStateState :: MonadState s (State s) where
get = State (\s -> Tuple s s)
psci/Main.hs
@@ -161,7 +161,6 @@ quitMessage = "See ya!"
161
162
-- |
163
-- Loads module, function, and file completions.
164
--- TODO: filter names to only include exported decls
165
--
166
completion :: CompletionFunc (StateT PSCiState IO)
167
completion = completeWord Nothing " \t\n\r" findCompletions
psci/Parser.hs
@@ -34,8 +34,7 @@ import qualified Language.PureScript as P
-- we actually want the normal @let@.
psciLet :: Parsec String P.ParseState Command
-psciLet = Let <$> (P.Let <$> (P.reserved "let" *> P.indented *> (Left <$> P.parseBinder))
- <*> (P.indented *> P.reservedOp "=" *> P.parseValue))
+psciLet = Let <$> (P.Let <$> (P.reserved "let" *> P.indented *> many1 P.parseDeclaration))
-- Parses PSCI metacommands or expressions input from the user.
purescript.cabal
@@ -33,8 +33,8 @@ library
Language.PureScript.Kinds
Language.PureScript.Names
Language.PureScript.Types
- Language.PureScript.Values
Language.PureScript.Scope
+ Language.PureScript.TypeClassDictionaries
Language.PureScript.DeadCodeElimination
Language.PureScript.Sugar
Language.PureScript.ModuleDependencies
@@ -44,7 +44,6 @@ library
Language.PureScript.Sugar.BindingGroups
Language.PureScript.Sugar.Operators
Language.PureScript.Sugar.TypeClasses
- Language.PureScript.Sugar.Let
Language.PureScript.Sugar.Names
Language.PureScript.CodeGen
Language.PureScript.CodeGen.Common
@@ -65,7 +64,6 @@ library
65
64
Language.PureScript.Parser.Kinds
66
Language.PureScript.Parser.State
67
Language.PureScript.Parser.Types
68
- Language.PureScript.Parser.Values
69
Language.PureScript.Pretty
70
Language.PureScript.Pretty.Common
71
Language.PureScript.Pretty.JS
src/Language/PureScript.hs
@@ -15,7 +15,6 @@
module Language.PureScript (module P, compile, compile', MonadMake(..), make) where
-import Language.PureScript.Values as P
import Language.PureScript.Types as P
import Language.PureScript.Kinds as P
import Language.PureScript.Declarations as P
src/Language/PureScript/CodeGen/Externs.hs
@@ -24,10 +24,10 @@ import qualified Data.Map as M
import Control.Monad.Writer
+import Language.PureScript.TypeClassDictionaries
import Language.PureScript.Declarations
import Language.PureScript.Pretty
import Language.PureScript.Names
-import Language.PureScript.Values
import Language.PureScript.Environment
src/Language/PureScript/CodeGen/JS.hs
@@ -30,7 +30,6 @@ import Control.Monad (replicateM, forM)
import qualified Data.Map as M
import Language.PureScript.Scope
@@ -134,6 +133,7 @@ valueToJs opts m e (Case values binders) = bindersToJs opts m e binders (map (va
134
133
valueToJs opts m e (IfThenElse cond th el) = JSConditional (valueToJs opts m e cond) (valueToJs opts m e th) (valueToJs opts m e el)
135
valueToJs opts m e (Accessor prop val) = JSAccessor prop (valueToJs opts m e val)
136
valueToJs opts m e (App val arg) = JSApp (valueToJs opts m e val) [valueToJs opts m e arg]
+valueToJs opts m e (Let ds val) = JSApp (JSFunction Nothing [] (JSBlock (concat (mapMaybe (flip (declToJs opts m) e) ds) ++ [JSReturn $ valueToJs opts m e val]))) []
137
valueToJs opts m e (Abs (Left arg) val) = JSFunction Nothing [identToJs arg] (JSBlock [JSReturn (valueToJs opts m (bindName m arg e) val)])
138
valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = let arg' = identToJs arg in JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn (valueToJs opts m e val)])
139
valueToJs _ m _ (Var ident) = varToJs m ident
src/Language/PureScript/DeadCodeElimination.hs
@@ -23,7 +23,6 @@ import Data.Generics
import Data.Maybe (mapMaybe)
0 commit comments