Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

update to 0.12 and psc-package #135

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exercises/chapter10/src/Control/Monad/Eff/Alert.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Control.Monad.Eff.Alert where
module Effect.Alert where

import Prelude

import Control.Monad.Eff (kind Effect, Eff)
import Effect (kind Effect, Effect)

foreign import data ALERT :: Effect

Expand Down
4 changes: 2 additions & 2 deletions exercises/chapter10/src/Control/Monad/Eff/Storage.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Control.Monad.Eff.Storage where
module Effect.Storage where

import Prelude

import Control.Monad.Eff (kind Effect, Eff)
import Effect (kind Effect, Effect)
import Data.Foreign (Foreign)

foreign import data STORAGE :: Effect
Expand Down
8 changes: 4 additions & 4 deletions exercises/chapter10/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Alert (ALERT, alert)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Storage (STORAGE, setItem, getItem)
import Effect (Effect)
import Effect.Alert (ALERT, alert)
import Effect.Console (log)
import Effect.Storage (STORAGE, setItem, getItem)
import Control.Monad.Except (runExcept)
import DOM (DOM)
import DOM.HTML (window)
Expand Down
2 changes: 2 additions & 0 deletions exercises/chapter11/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/output/
/node_modules/
/bower_components/
.psc-package
.psc-package
30 changes: 0 additions & 30 deletions exercises/chapter11/bower.json

This file was deleted.

12 changes: 12 additions & 0 deletions exercises/chapter11/psc-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "chapter2",
"set": "psc-0.12.0-20180625-2",
"source": "https://github.com/purescript/package-sets.git",
"depends": [
"node-readline",
"ordered-collections",
"strings",
"transformers",
"yargs"
]
}
4 changes: 2 additions & 2 deletions exercises/chapter11/src/Game.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Data.Map as M
import Data.Set as S
import Control.Monad.RWS (RWS)
import Control.Monad.Reader.Class (ask)
import Control.Monad.State.Class (get, modify, put)
import Control.Monad.State.Class (get, modify_, put)
import Control.Monad.Writer.Class (tell)
import Data.Coords (Coords(..), prettyPrintCoords, coords)
import Data.Foldable (for_)
Expand Down Expand Up @@ -42,7 +42,7 @@ pickUp item = do
_ -> tell (L.singleton "I don't see that item here.")

move :: Int -> Int -> Game Unit
move dx dy = modify (\(GameState state) -> GameState (state { player = updateCoords state.player }))
move dx dy = modify_ (\(GameState state) -> GameState (state { player = updateCoords state.player }))
where
updateCoords :: Coords -> Coords
updateCoords (Coords p) = coords (p.x + dx) (p.y + dy)
Expand Down
25 changes: 6 additions & 19 deletions exercises/chapter11/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ module Main where

import Prelude
import Node.ReadLine as RL
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (EXCEPTION)
import Effect (Effect)
import Effect.Console (log)
import Control.Monad.RWS (RWSResult(..), runRWS)
import Data.Either (Either(..))
import Data.Foldable (for_)
Expand All @@ -18,13 +17,8 @@ import Node.Yargs.Applicative (Y, runY, flag, yarg)
import Node.Yargs.Setup (usage)

runGame
:: forall eff
. GameEnvironment
-> Eff ( exception :: EXCEPTION
, readline :: RL.READLINE
, console :: CONSOLE
| eff
) Unit
:: GameEnvironment
-> Effect Unit
runGame env = do
interface <- RL.createConsoleInterface RL.noCompletion
RL.setPrompt "> " 2 interface
Expand All @@ -33,11 +27,7 @@ runGame env = do
lineHandler
:: GameState
-> String
-> Eff ( exception :: EXCEPTION
, console :: CONSOLE
, readline :: RL.READLINE
| eff
) Unit
-> Effect Unit
lineHandler currentState input = do
case runRWS (game (split (wrap " ") input)) env currentState of
RWSResult state _ written -> do
Expand All @@ -51,10 +41,7 @@ runGame env = do

pure unit

main :: Eff ( exception :: EXCEPTION
, console :: CONSOLE
, readline :: RL.READLINE
) Unit
main :: Effect Unit
main = runY (usage "$0 -p <player name>") $ map runGame env
where
env :: Y GameEnvironment
Expand Down
1 change: 1 addition & 0 deletions exercises/chapter12/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/output/
/node_modules/
/bower_components/
.psc-package
31 changes: 0 additions & 31 deletions exercises/chapter12/bower.json

This file was deleted.

16 changes: 16 additions & 0 deletions exercises/chapter12/psc-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "chapter2",
"set": "psc-0.12.0-20180625",
"source": "https://github.com/purescript/package-sets.git",
"depends": [
"console",
"functions",
"lists",
"math",
"parallel",
"prelude",
"refs",
"strings",
"transformers"
]
}
34 changes: 16 additions & 18 deletions exercises/chapter12/src/Files.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,48 @@ module Files where
import Prelude

import Control.Monad.Cont.Trans (ContT(..))
import Control.Monad.Eff (kind Effect, Eff)
import Effect (Effect)
import Control.Monad.Except.Trans (ExceptT(..))
import Data.Either (Either(..))
import Data.Function.Uncurried (Fn4, Fn3, runFn4, runFn3)
import Types (Async)

foreign import data FS :: Effect

type ErrorCode = String

type FilePath = String

foreign import readFileImpl ::
forall eff. Fn3 FilePath
(String -> Eff (fs :: FS | eff) Unit)
(ErrorCode -> Eff (fs :: FS | eff) Unit)
(Eff (fs :: FS | eff) Unit)
Fn3 FilePath
(String -> Effect Unit)
(ErrorCode -> Effect Unit)
(Effect Unit)

foreign import writeFileImpl ::
forall eff. Fn4 FilePath
Fn4 FilePath
String
(Eff (fs :: FS | eff) Unit)
(ErrorCode -> Eff (fs :: FS | eff) Unit)
(Eff (fs :: FS | eff) Unit)
(Effect Unit)
(ErrorCode -> Effect Unit)
(Effect Unit)

readFile :: forall eff. FilePath -> (Either ErrorCode String -> Eff (fs :: FS | eff) Unit) -> Eff (fs :: FS | eff) Unit
readFile :: FilePath -> (Either ErrorCode String -> Effect Unit) -> Effect Unit
readFile path k = runFn3 readFileImpl path (k <<< Right) (k <<< Left)

writeFile :: forall eff. FilePath -> String -> (Either ErrorCode Unit -> Eff (fs :: FS | eff) Unit) -> Eff (fs :: FS | eff) Unit
writeFile :: FilePath -> String -> (Either ErrorCode Unit -> Effect Unit) -> Effect Unit
writeFile path text k = runFn4 writeFileImpl path text (k $ Right unit) (k <<< Left)

readFileCont :: forall eff. FilePath -> Async (fs :: FS | eff) (Either ErrorCode String)
readFileCont :: FilePath -> Async (Either ErrorCode String)
readFileCont path = ContT $ readFile path

writeFileCont :: forall eff. FilePath -> String -> Async (fs :: FS | eff) (Either ErrorCode Unit)
writeFileCont :: FilePath -> String -> Async (Either ErrorCode Unit)
writeFileCont path text = ContT $ writeFile path text

readFileContEx :: forall eff. FilePath -> ExceptT ErrorCode (Async (fs :: FS | eff)) String
readFileContEx :: FilePath -> ExceptT ErrorCode Async String
readFileContEx path = ExceptT $ readFileCont path

writeFileContEx :: forall eff. FilePath -> String -> ExceptT ErrorCode (Async (fs :: FS | eff)) Unit
writeFileContEx :: FilePath -> String -> ExceptT ErrorCode Async Unit
writeFileContEx path text = ExceptT $ writeFileCont path text

copyFileContEx :: forall eff. FilePath -> FilePath -> ExceptT ErrorCode (Async (fs :: FS | eff)) Unit
copyFileContEx :: FilePath -> FilePath -> ExceptT ErrorCode Async Unit
copyFileContEx src dest = do
content <- readFileContEx src
writeFileContEx dest content
12 changes: 5 additions & 7 deletions exercises/chapter12/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ module Main where
import Prelude

import Control.Monad.Cont.Trans (runContT)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log, error)
import Effect (Effect)
import Effect.Console (log, error)
import Control.Monad.Trans.Class (lift)
import Data.Either (either)
import Network.HTTP.Client (HTTP, get)
import Network.HTTP.Client (get)
import Types (Async)

main :: Eff ( http :: HTTP
, console :: CONSOLE
) Unit
main :: Effect Unit
main = async do
response <- get "http://purescript.org"
lift (either error log response)
where
async :: forall eff. Async eff Unit -> Eff eff Unit
async :: Async Unit -> Effect Unit
async = flip runContT pure
14 changes: 6 additions & 8 deletions exercises/chapter12/src/Network/HTTP/Client.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ module Network.HTTP.Client where
import Prelude

import Control.Monad.Cont.Trans (ContT(..))
import Control.Monad.Eff (kind Effect, Eff)
import Effect (Effect)
import Data.Either (Either(..))
import Data.Function.Uncurried (Fn3, runFn3)
import Types (Async)

foreign import data HTTP :: Effect

type URI = String

foreign import getImpl ::
forall eff. Fn3 URI
(String -> Eff (http :: HTTP | eff) Unit)
(String -> Eff (http :: HTTP | eff) Unit)
(Eff (http :: HTTP | eff) Unit)
Fn3 URI
(String -> Effect Unit)
(String -> Effect Unit)
(Effect Unit)

get :: forall eff. URI -> Async (http :: HTTP | eff) (Either String String)
get :: URI -> Async (Either String String)
get req = ContT $ \k -> runFn3 getImpl req (k <<< Right) (k <<< Left)
4 changes: 2 additions & 2 deletions exercises/chapter12/src/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Types where

import Prelude

import Control.Monad.Eff (Eff)
import Effect (Effect)
import Control.Monad.Cont.Trans (ContT)

type Async eff = ContT Unit (Eff eff)
type Async = ContT Unit Effect
1 change: 1 addition & 0 deletions exercises/chapter13/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/output/
/node_modules/
/bower_components/
.psc-package
28 changes: 0 additions & 28 deletions exercises/chapter13/bower.json

This file was deleted.

14 changes: 14 additions & 0 deletions exercises/chapter13/psc-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "chapter2",
"set": "psc-0.12.0-20180625",
"source": "https://github.com/purescript/package-sets.git",
"depends": [
"arrays",
"console",
"functions",
"lists",
"math",
"prelude",
"quickcheck"
]
}
2 changes: 1 addition & 1 deletion exercises/chapter13/src/Merge.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ merge :: Array Int -> Array Int -> Array Int
merge = mergePoly

mergePoly :: forall a. Ord a => Array a -> Array a -> Array a
mergePoly = mergeWith id
mergePoly = mergeWith identity

mergeWith :: forall a b. Ord b => (a -> b) -> Array a -> Array a -> Array a
mergeWith f = \xs ys ->
Expand Down
Loading