From c89e20f0cd0b078868c901ef5b26c7421c8728a2 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 19 Feb 2020 09:12:09 +0000 Subject: [PATCH 01/45] Make sure src/ci can fail --- src/ci | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ci b/src/ci index add9e4c..2e96a8d 100755 --- a/src/ci +++ b/src/ci @@ -1,15 +1,17 @@ #!/usr/bin/env bash +set -e + echo -n "01-basics .. " -cd 01-basics && bash ci && cd .. +(cd 01-basics && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "02-monads .. " -cd 02-monads && bash ci && cd .. +(cd 02-monads && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "03-transformers .. " -cd 03-monad-transformers && bash ci && cd .. +(cd 03-monad-transformers && bash ci) echo -e "\e[1;32mOK\e[0m" #echo -n "04-extensions .. " @@ -17,29 +19,29 @@ echo -e "\e[1;32mOK\e[0m" #echo -e "\e[1;32mOK\e[0m" echo -n "05-laziness .. " -cd 05-laziness && bash ci && cd .. +(cd 05-laziness && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "06-prelude .. " -cd 06-prelude && bash ci && cd .. +(cd 06-prelude && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "07-text-bytestring .. " -cd 07-text-bytestring && bash ci && cd .. +(cd 07-text-bytestring && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "29-ghc .. " -cd 29-ghc && bash ci && cd .. +(cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "30-languages .. " -cd 30-languages && bash ci && cd .. +(cd 30-languages && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "33-categories .. " -cd 33-categories && bash ci && cd .. +(cd 33-categories && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "34-time .. " -cd 34-time && bash ci && cd .. +(cd 34-time && bash ci) echo -e "\e[1;32mOK\e[0m" From 196b8710f494fafed46067f7f37644f646de3f33 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 12:09:14 +0000 Subject: [PATCH 02/45] Fix split bounds --- src/06-prelude/split.hs | 1 + src/06-prelude/stack.yaml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/06-prelude/split.hs b/src/06-prelude/split.hs index 9f1064d..1c3e151 100644 --- a/src/06-prelude/split.hs +++ b/src/06-prelude/split.hs @@ -2,6 +2,7 @@ import Data.List.Split example1 :: [String] example1 = splitOn "." "foo.bar.baz" + -- ["foo","bar","baz"] example2 :: [String] diff --git a/src/06-prelude/stack.yaml b/src/06-prelude/stack.yaml index 6ae77d1..2b9707c 100644 --- a/src/06-prelude/stack.yaml +++ b/src/06-prelude/stack.yaml @@ -1,2 +1,3 @@ -resolver: lts-14.7 -extra-deps: [] +resolver: lts-14.20 +extra-deps: + - split-0.2.3.3 From 5653eabe395404a3bb1bb2c54fb8924b7fb5c8c0 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 14:00:28 +0000 Subject: [PATCH 03/45] Chapter 8 CI --- src/06-prelude/example.cabal | 28 ++++++++--------- src/08-applicatives/ci | 5 +++ src/ci | 4 +++ tutorial.md | 59 ++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 14 deletions(-) create mode 100755 src/08-applicatives/ci diff --git a/src/06-prelude/example.cabal b/src/06-prelude/example.cabal index bb7b38d..e77e475 100644 --- a/src/06-prelude/example.cabal +++ b/src/06-prelude/example.cabal @@ -1,15 +1,15 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2020 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - default-language: Haskell2010 - build-depends: - base >= 4.6 && <4.14, - transformers >= 0.5 && <0.6, - split >= 0.2 && <0.3 +library + default-language: Haskell2010 + build-depends: + base >=4.6 && <4.14 + , split >=0.2.3.3 && <0.3 + , transformers >=0.5 && <0.6 diff --git a/src/08-applicatives/ci b/src/08-applicatives/ci new file mode 100755 index 0000000..2763dc3 --- /dev/null +++ b/src/08-applicatives/ci @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive applicative.hs +stack exec ghc -- -e ":q" --interactive variadic.hs diff --git a/src/ci b/src/ci index 2e96a8d..8407a7e 100755 --- a/src/ci +++ b/src/ci @@ -30,6 +30,10 @@ echo -n "07-text-bytestring .. " (cd 07-text-bytestring && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "08-applicatives .. " +(cd 08-applicatives && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" diff --git a/tutorial.md b/tutorial.md index 5ceec08..1e0f594 100644 --- a/tutorial.md +++ b/tutorial.md @@ -7770,6 +7770,65 @@ require a precise subset of error handling methods. * `MonadMask` - Monads which expose a interface for masking asynchronous exceptions. +There are three core primitives that are used in handling runtime exceptions: + +* `finally` - For handling guaranteed finalisation of code in the presence of exceptions. +* `onException` - For handing exception case only if an exception is thrown. +* `bracket` - For implementing resource handling with custom acquisition and finalizer logic, in the presence of exceptions. + +`finally` takes an `IO` action to run as a computation and a secondary function +to run after the evaluation of the first. + +```haskell +finally :: IO a -- ^ computation to run first + -> IO b -- ^ computation to run afterward (even if an exception was raised) + -> IO a -- returns the value from the first computation +``` + +`onException` has a similar signature but the second function is run **only if** +an exception is raised. + +```haskell +onException :: IO a -> IO b -> IO a +``` + +The `bracket` function takes two functions, an acquisition function and a +finalizer function which "bracket" the evaluation of the third. The finaliser +will be run if the computation throwns an exception and unwinds. + +```haskell +bracket + :: IO a -- ^ computation to run first + -> (a -> IO b) -- ^ computation to run last + -> (a -> IO c) -- ^ computation to run in-between + -> IO c -- returns the value from the in-between computation +``` + +A simple example of usage is bracket logic that handles file descriptors which +need to be explicitly closed after evaluation is done. The initialiser in this +case will return a file descriptor to the body and then run `hClose` on the file +descriptor after the body is done with evaluation. + +```haskell +bracket + (openFile "myfile" ReadMode) -- acquisition + (hClose) -- finaliser + (\fileHandle -> ... ) -- body +``` + +In addition the `exceptions` library exposes several functions for explicitly +handling a variety of exceptions of various forms. Toplevel handlers that need +to "catch em' all" should use `catchAny` for wildcard error handling. + +```haskell +catch :: (MonadCatch m, Exception e) => m a -> (e -> m a) -> m a +catchIO :: MonadCatch m => m a -> (IOException -> m a) -> m a +catchAny :: MonadCatch m => m a -> (SomeException -> m a) -> m a +catchAsync :: (MonadCatch m, Exception e) => m a -> (e -> m a) -> m a +``` + +A simple example of usage: + ~~~~ {.haskell include="src/09-errors/exceptions.hs"} ~~~~ From e41e6ecfe190096ea58c19f222483b9af98b0c40 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 16:08:35 +0000 Subject: [PATCH 04/45] Chapter 10 CI --- src/09-errors/ci | 10 ++++++++++ src/09-errors/eithert.hs | 22 ---------------------- src/09-errors/errors.hs | 11 ++++------- src/09-errors/example.cabal | 7 +++++-- src/09-errors/stack.yaml | 27 +-------------------------- src/10-advanced-monads/ci | 17 +++++++++++++++++ src/10-advanced-monads/example.cabal | 6 +++--- src/10-advanced-monads/free_impl.hs | 25 ++++++++++++++++++++----- src/10-advanced-monads/st.hs | 13 ++++--------- src/10-advanced-monads/stack.yaml | 28 +--------------------------- src/ci | 8 ++++++++ 11 files changed, 73 insertions(+), 101 deletions(-) create mode 100755 src/09-errors/ci delete mode 100644 src/09-errors/eithert.hs create mode 100755 src/10-advanced-monads/ci diff --git a/src/09-errors/ci b/src/09-errors/ci new file mode 100755 index 0000000..fe4a7a6 --- /dev/null +++ b/src/09-errors/ci @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive either.hs +#stack exec ghc -- -e ":q" --interactive either_impl.hs +stack exec ghc -- -e ":q" --interactive errors.hs +stack exec ghc -- -e ":q" --interactive exceptions.hs +stack exec ghc -- -e ":q" --interactive exceptt.hs +stack exec ghc -- -e ":q" --interactive ioexception.hs +stack exec ghc -- -e ":q" --interactive spoon.hs diff --git a/src/09-errors/eithert.hs b/src/09-errors/eithert.hs deleted file mode 100644 index f87b6ba..0000000 --- a/src/09-errors/eithert.hs +++ /dev/null @@ -1,22 +0,0 @@ -import Control.Error -import Control.Monad.Trans - -data Failure - = NonPositive Int - | ReadError String - deriving Show - -main :: IO () -main = do - putStrLn "Enter a positive number." - s <- getLine - - e <- runEitherT $ do - n <- tryRead (ReadError s) s - if n > 0 - then return $ n + 1 - else throwT $ NonPositive n - - case e of - Left n -> putStrLn $ "Failed with: " ++ show n - Right s -> putStrLn $ "Succeeded with: " ++ show s diff --git a/src/09-errors/errors.hs b/src/09-errors/errors.hs index 6d2da9c..2c99030 100644 --- a/src/09-errors/errors.hs +++ b/src/09-errors/errors.hs @@ -1,15 +1,12 @@ -import Control.Monad.Error +import Control.Monad.Except import Control.Monad.Identity data Exception = Failure String | GenericFailure - deriving Show + deriving (Show) -instance Error Exception where - noMsg = GenericFailure - -type ErrMonad a = ErrorT Exception Identity a +type ErrMonad a = ExceptT Exception Identity a example :: Int -> Int -> ErrMonad Int example x y = do @@ -18,7 +15,7 @@ example x y = do x -> return $ x `div` y runFail :: ErrMonad a -> Either Exception a -runFail = runIdentity . runErrorT +runFail = runIdentity . runExceptT example1 :: Either Exception Int example1 = runFail $ example 2 3 diff --git a/src/09-errors/example.cabal b/src/09-errors/example.cabal index 8233ff7..6b3ca38 100644 --- a/src/09-errors/example.cabal +++ b/src/09-errors/example.cabal @@ -11,8 +11,11 @@ tested-with: GHC == 7.6.3 library build-depends: + base >= 4.6 && <4.14, spoon >= 0.3 && <0.4, - mtl >= 2.2 && <2.3, - base >= 4.6 && <4.10 + errors >= 2.3 && <2.4, + either >= 4.4 && <5.1, + transformers >= 0.5 && <0.6, + mtl >= 2.2 && <2.3 default-language: Haskell2010 diff --git a/src/09-errors/stack.yaml b/src/09-errors/stack.yaml index d1bcc2f..bfa9ef4 100644 --- a/src/09-errors/stack.yaml +++ b/src/09-errors/stack.yaml @@ -1,32 +1,7 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md - # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-4.2 - -# Local packages, usually specified by relative directory name +resolver: lts-14.20 packages: - '.' - -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: [] - -# Override default flag values for local packages and extra-deps flags: {} - -# Extra package databases containing global packages extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] diff --git a/src/10-advanced-monads/ci b/src/10-advanced-monads/ci new file mode 100755 index 0000000..c5eb33a --- /dev/null +++ b/src/10-advanced-monads/ci @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive base.hs +stack exec ghc -- -e ":q" --interactive cont.hs +#stack exec ghc -- -e ":q" --interactive cont_impl.hs +stack exec ghc -- -e ":q" --interactive free_dsl.hs +stack exec ghc -- -e ":q" --interactive free_impl.hs +stack exec ghc -- -e ":q" --interactive function.hs +#stack exec ghc -- -e ":q" --interactive indexed.hs +stack exec ghc -- -e ":q" --interactive logict.hs +stack exec ghc -- -e ":q" --interactive mmorph.hs +stack exec ghc -- -e ":q" --interactive monadfix.hs +stack exec ghc -- -e ":q" --interactive monadplus.hs +stack exec ghc -- -e ":q" --interactive partiality.hs +stack exec ghc -- -e ":q" --interactive rws.hs +stack exec ghc -- -e ":q" --interactive st.hs diff --git a/src/10-advanced-monads/example.cabal b/src/10-advanced-monads/example.cabal index 6314569..3e0d944 100644 --- a/src/10-advanced-monads/example.cabal +++ b/src/10-advanced-monads/example.cabal @@ -11,12 +11,12 @@ tested-with: GHC == 7.6.3 library build-depends: + base >= 4.6 && <4.14, safe >= 0.3 && <0.4, - mmorph >= 1.0 && <1.1, + mmorph >= 1.0 && <1.5, mtl >= 2.2 && <2.3, transformers-base >= 0.4 && <0.5, monad-control >= 1.0 && <1.1, - lifted-base >= 0.2 && <0.3, - base >= 4.6 && <4.10 + lifted-base >= 0.2 && <0.3 default-language: Haskell2010 diff --git a/src/10-advanced-monads/free_impl.hs b/src/10-advanced-monads/free_impl.hs index 90ba9c2..6aba5dd 100644 --- a/src/10-advanced-monads/free_impl.hs +++ b/src/10-advanced-monads/free_impl.hs @@ -1,19 +1,34 @@ +{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} -import Control.Applicative - data Free f a = Pure a | Free (f (Free f a)) -instance Functor f => Monad (Free f) where - return a = Pure a +instance Functor f => Functor (Free f) where + fmap f (Pure a) = Pure (f a) + fmap f x = go x + where + go (Free fa) = Free (go <$> fa) + +instance Applicative f => Applicative (Free f) where + pure = Pure + Pure a <*> Pure b = Pure $ a b + Pure a <*> Free mb = Free $ fmap a <$> mb + Free ma <*> Pure b = Free $ fmap ($ b) <$> ma + Free ma <*> Free mb = Free $ fmap (<*>) ma <*> mb + +instance Applicative f => Monad (Free f) where + return = Pure Pure a >>= f = f a Free f >>= g = Free (fmap (>>= g) f) -class Monad m => MonadFree f m where +class Monad m => MonadFree f m where wrap :: f (m a) -> m a +instance Applicative f => MonadFree f (Free f) where + wrap = Free + liftF :: (Functor f, MonadFree f m) => f a -> m a liftF = wrap . fmap return diff --git a/src/10-advanced-monads/st.hs b/src/10-advanced-monads/st.hs index 7e80992..2d34065 100644 --- a/src/10-advanced-monads/st.hs +++ b/src/10-advanced-monads/st.hs @@ -1,27 +1,22 @@ -import Data.STRef import Control.Monad import Control.Monad.ST import Control.Monad.State.Strict +import Data.STRef example1 :: Int example1 = runST $ do x <- newSTRef 0 - - forM_ [1..1000] $ \j -> do + forM_ [1 .. 1000] $ \j -> do writeSTRef x j - readSTRef x example2 :: Int example2 = runST $ do count <- newSTRef 0 - replicateM_ (10^6) $ modifySTRef' count (+1) + replicateM_ (10 ^ 6) $ modifySTRef' count (+ 1) readSTRef count example3 :: Int example3 = flip evalState 0 $ do - replicateM_ (10^6) $ modify' (+1) + replicateM_ (10 ^ 6) $ modify' (+ 1) get - -modify' :: MonadState a m => (a -> a) -> m () -modify' f = get >>= (\x -> put $! f x) diff --git a/src/10-advanced-monads/stack.yaml b/src/10-advanced-monads/stack.yaml index d1bcc2f..f0eb25e 100644 --- a/src/10-advanced-monads/stack.yaml +++ b/src/10-advanced-monads/stack.yaml @@ -1,32 +1,6 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md - -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-4.2 - -# Local packages, usually specified by relative directory name +resolver: lts-14.20 packages: - '.' - -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: [] - -# Override default flag values for local packages and extra-deps flags: {} - -# Extra package databases containing global packages extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] diff --git a/src/ci b/src/ci index 8407a7e..3c9fd59 100755 --- a/src/ci +++ b/src/ci @@ -34,6 +34,14 @@ echo -n "08-applicatives .. " (cd 08-applicatives && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "09-errors .. " +(cd 09-errors && bash ci) +echo -e "\e[1;32mOK\e[0m" + +echo -n "10-advanced-monads .. " +(cd 10-advanced-monads && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 662ce17c9f7fb8edf0459f961ccc310369aebda7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 16:26:10 +0000 Subject: [PATCH 05/45] Chapter 12 CI --- src/06-prelude/split.hs | 1 - src/11-quantification/ci | 9 +++++++++ src/11-quantification/example.cabal | 2 +- src/11-quantification/stack.yaml | 28 +--------------------------- src/11-quantification/test.sh | 3 --- src/12-gadts/README.md | 11 ----------- src/12-gadts/ci | 9 +++++++++ src/12-gadts/example.cabal | 16 ++++++++++++++++ src/12-gadts/propositional_equal.hs | 5 ++--- src/12-gadts/stack.yaml | 6 ++++++ src/ci | 8 ++++++++ 11 files changed, 52 insertions(+), 46 deletions(-) create mode 100755 src/11-quantification/ci delete mode 100755 src/11-quantification/test.sh delete mode 100644 src/12-gadts/README.md create mode 100755 src/12-gadts/ci create mode 100644 src/12-gadts/example.cabal create mode 100644 src/12-gadts/stack.yaml diff --git a/src/06-prelude/split.hs b/src/06-prelude/split.hs index 1c3e151..9f1064d 100644 --- a/src/06-prelude/split.hs +++ b/src/06-prelude/split.hs @@ -2,7 +2,6 @@ import Data.List.Split example1 :: [String] example1 = splitOn "." "foo.bar.baz" - -- ["foo","bar","baz"] example2 :: [String] diff --git a/src/11-quantification/ci b/src/11-quantification/ci new file mode 100755 index 0000000..219b4fc --- /dev/null +++ b/src/11-quantification/ci @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive existential.hs +stack exec ghc -- -e ":q" --interactive impredicative.hs +#stack exec ghc -- -e ":q" --interactive rankn.hs +#stack exec ghc -- -e ":q" --interactive scopedtvars.hs +#stack exec ghc -- -e ":q" --interactive skolem_capture.hs +stack exec ghc -- -e ":q" --interactive universal.hs diff --git a/src/11-quantification/example.cabal b/src/11-quantification/example.cabal index d35d8cb..f491715 100644 --- a/src/11-quantification/example.cabal +++ b/src/11-quantification/example.cabal @@ -11,6 +11,6 @@ tested-with: GHC == 7.6.3 library build-depends: - base >= 4.6 && <4.10 + base >= 4.6 && <4.14 default-language: Haskell2010 diff --git a/src/11-quantification/stack.yaml b/src/11-quantification/stack.yaml index d1bcc2f..f0eb25e 100644 --- a/src/11-quantification/stack.yaml +++ b/src/11-quantification/stack.yaml @@ -1,32 +1,6 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md - -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-4.2 - -# Local packages, usually specified by relative directory name +resolver: lts-14.20 packages: - '.' - -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: [] - -# Override default flag values for local packages and extra-deps flags: {} - -# Extra package databases containing global packages extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] diff --git a/src/11-quantification/test.sh b/src/11-quantification/test.sh deleted file mode 100755 index fc09c78..0000000 --- a/src/11-quantification/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -for f in *.hs; do - echo ":quit" | stack exec ghci $f -done diff --git a/src/12-gadts/README.md b/src/12-gadts/README.md deleted file mode 100644 index 526fce8..0000000 --- a/src/12-gadts/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Generalized Algebraic Datatypes -=============================== - -```bash -$ stack exec ghci equal.hs -$ stack exec ghci gadt.hs -$ stack exec ghci kindsignatures.hs -$ stack exec ghci phantom.hs -$ stack exec ghci phantom_example.hs -$ stack exec ghci propositional_equal.hs -``` diff --git a/src/12-gadts/ci b/src/12-gadts/ci new file mode 100755 index 0000000..a7a0ac5 --- /dev/null +++ b/src/12-gadts/ci @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive equal.hs +stack exec ghc -- -e ":q" --interactive gadt.hs +stack exec ghc -- -e ":q" --interactive kindsignatures.hs +#stack exec ghc -- -e ":q" --interactive phantom.hs +stack exec ghc -- -e ":q" --interactive phantom_example.hs +stack exec ghc -- -e ":q" --interactive propositional_equal.hs diff --git a/src/12-gadts/example.cabal b/src/12-gadts/example.cabal new file mode 100644 index 0000000..f491715 --- /dev/null +++ b/src/12-gadts/example.cabal @@ -0,0 +1,16 @@ +name: example +version: 0.1 +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +copyright: 2016 Stephen Diehl +category: Documentation +build-type: Simple +cabal-version: >=1.10 +tested-with: GHC == 7.6.3 + +library + + build-depends: + base >= 4.6 && <4.14 + + default-language: Haskell2010 diff --git a/src/12-gadts/propositional_equal.hs b/src/12-gadts/propositional_equal.hs index 982a3a2..b115714 100644 --- a/src/12-gadts/propositional_equal.hs +++ b/src/12-gadts/propositional_equal.hs @@ -1,7 +1,7 @@ -{-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-} -{-# LANGUAGE PolyKinds #-} {-# LANGUAGE ExplicitForAll #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE PolyKinds #-} {-# LANGUAGE TypeOperators #-} -- a ≡ b @@ -24,7 +24,6 @@ trans Refl Refl = Refl cast :: a :~: b -> a -> b cast Refl = id - a :: forall n. n :~: n a = Refl diff --git a/src/12-gadts/stack.yaml b/src/12-gadts/stack.yaml new file mode 100644 index 0000000..f0eb25e --- /dev/null +++ b/src/12-gadts/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-14.20 +packages: +- '.' +extra-deps: [] +flags: {} +extra-package-dbs: [] diff --git a/src/ci b/src/ci index 3c9fd59..50a0026 100755 --- a/src/ci +++ b/src/ci @@ -42,6 +42,14 @@ echo -n "10-advanced-monads .. " (cd 10-advanced-monads && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "11-quantification .. " +(cd 11-quantification && bash ci) +echo -e "\e[1;32mOK\e[0m" + +echo -n "12-gadts .. " +(cd 12-gadts && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 835398caf065684ce55f65e6da3d1a06146c4f8e Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 16:28:35 +0000 Subject: [PATCH 06/45] Chapter 14 CI --- src/13-lambda-calculus/example.cabal | 16 ++++++++++++++++ src/13-lambda-calculus/stack.yaml | 6 ++++++ src/14-interpreters/ci | 10 ++++++++++ src/ci | 4 ++++ 4 files changed, 36 insertions(+) create mode 100644 src/13-lambda-calculus/example.cabal create mode 100644 src/13-lambda-calculus/stack.yaml create mode 100755 src/14-interpreters/ci diff --git a/src/13-lambda-calculus/example.cabal b/src/13-lambda-calculus/example.cabal new file mode 100644 index 0000000..f491715 --- /dev/null +++ b/src/13-lambda-calculus/example.cabal @@ -0,0 +1,16 @@ +name: example +version: 0.1 +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +copyright: 2016 Stephen Diehl +category: Documentation +build-type: Simple +cabal-version: >=1.10 +tested-with: GHC == 7.6.3 + +library + + build-depends: + base >= 4.6 && <4.14 + + default-language: Haskell2010 diff --git a/src/13-lambda-calculus/stack.yaml b/src/13-lambda-calculus/stack.yaml new file mode 100644 index 0000000..f0eb25e --- /dev/null +++ b/src/13-lambda-calculus/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-14.20 +packages: +- '.' +extra-deps: [] +flags: {} +extra-package-dbs: [] diff --git a/src/14-interpreters/ci b/src/14-interpreters/ci new file mode 100755 index 0000000..65f5579 --- /dev/null +++ b/src/14-interpreters/ci @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive catamorphism.hs +stack exec ghc -- -e ":q" --interactive factorial.hs +stack exec ghc -- -e ":q" --interactive fext.hs +stack exec ghc -- -e ":q" --interactive final.hs +stack exec ghc -- -e ":q" --interactive initial.hs +stack exec ghc -- -e ":q" --interactive initial_interpreter.hs +stack exec ghc -- -e ":q" --interactive recursion_schemes.hs diff --git a/src/ci b/src/ci index 50a0026..80c0ffb 100755 --- a/src/ci +++ b/src/ci @@ -50,6 +50,10 @@ echo -n "12-gadts .. " (cd 12-gadts && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "14-interpreters .. " +(cd 14-interpreters && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 14921134fe325f4f8a080a8f0cb7762d40a34bd7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 16:39:31 +0000 Subject: [PATCH 07/45] Chapter 15 CI --- src/15-testing/ci | 12 +++++++++++ src/15-testing/criterion.hs | 29 +++++++++++++------------ src/15-testing/example.cabal | 13 +++++++---- src/15-testing/quickspec.hs | 42 ++++++++++++++++-------------------- src/15-testing/stack.yaml | 32 ++++----------------------- src/ci | 4 ++++ 6 files changed, 62 insertions(+), 70 deletions(-) create mode 100755 src/15-testing/ci diff --git a/src/15-testing/ci b/src/15-testing/ci new file mode 100755 index 0000000..e1d560f --- /dev/null +++ b/src/15-testing/ci @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive arbitrary.hs +stack exec ghc -- -e ":q" --interactive criterion.hs +stack exec ghc -- -e ":q" --interactive qcheck.hs +#stack exec ghc -- -e ":q" --interactive quickspec.hs +stack exec ghc -- -e ":q" --interactive silently.hs +stack exec ghc -- -e ":q" --interactive smallcheck.hs +stack exec ghc -- -e ":q" --interactive smallcheck_series.hs +stack exec ghc -- -e ":q" --interactive smallcheck_tree.hs +stack exec ghc -- -e ":q" --interactive tasty.hs diff --git a/src/15-testing/criterion.hs b/src/15-testing/criterion.hs index 7669b51..dcbbc45 100644 --- a/src/15-testing/criterion.hs +++ b/src/15-testing/criterion.hs @@ -1,29 +1,30 @@ import Criterion.Main -import Criterion.Config -- Naive recursion for fibonacci numbers. fib1 :: Int -> Int fib1 0 = 0 fib1 1 = 1 -fib1 n = fib1 (n-1) + fib1 (n-2) +fib1 n = fib1 (n -1) + fib1 (n -2) -- Use the De Moivre closed form for fibonacci numbers. fib2 :: Int -> Int -fib2 x = truncate $ ( 1 / sqrt 5 ) * ( phi ^ x - psi ^ x ) +fib2 x = truncate $ (1 / sqrt 5) * (phi ^ x - psi ^ x) where - phi = ( 1 + sqrt 5 ) / 2 - psi = ( 1 - sqrt 5 ) / 2 + phi = (1 + sqrt 5) / 2 + psi = (1 - sqrt 5) / 2 suite :: [Benchmark] -suite = [ - bgroup "naive" [ - bench "fib 10" $ whnf fib1 5 - , bench "fib 20" $ whnf fib1 10 - ], - bgroup "de moivre" [ - bench "fib 10" $ whnf fib2 5 - , bench "fib 20" $ whnf fib2 10 - ] +suite = + [ bgroup + "naive" + [ bench "fib 10" $ whnf fib1 5, + bench "fib 20" $ whnf fib1 10 + ], + bgroup + "de moivre" + [ bench "fib 10" $ whnf fib2 5, + bench "fib 20" $ whnf fib2 10 + ] ] main :: IO () diff --git a/src/15-testing/example.cabal b/src/15-testing/example.cabal index 74d94e6..371e7d7 100644 --- a/src/15-testing/example.cabal +++ b/src/15-testing/example.cabal @@ -11,9 +11,14 @@ tested-with: GHC == 7.6.3 library build-depends: - tasty >= 0.11 && <0.12, - tasty-hunit >= 0.9 && <0.10, - silently >= 1.2 && <1.3, - base >= 4.6 && <4.10 + base >= 4.6 && <4.14, + tasty >= 1.2 && <1.3, + tasty-hunit >= 0.9 && <0.11, + tasty-quickcheck >= 0.10 && <0.11, + tasty-smallcheck >= 0.8 && <0.9, + silently >= 1.2 && <1.3, + quickspec >= 2.1 && <2.2, + smallcheck >= 1.1 && <1.2, + criterion -any default-language: Haskell2010 diff --git a/src/15-testing/quickspec.hs b/src/15-testing/quickspec.hs index c18c0c8..1353d93 100644 --- a/src/15-testing/quickspec.hs +++ b/src/15-testing/quickspec.hs @@ -1,48 +1,42 @@ -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeOperators #-} import Data.List import Data.Typeable - -import Test.QuickSpec hiding (lists, bools, arith) -import Test.QuickCheck +import QuickSpec hiding (arith, bools, lists) +import Test.QuickCheck.Arbitrary type Var k a = (Typeable a, Arbitrary a, CoArbitrary a, k a) listCons :: forall a. Var Ord a => a -> Sig -listCons a = background - [ - "[]" `fun0` ([] :: [a]), - ":" `fun2` ((:) :: a -> [a] -> [a]) - ] +listCons a = + background + [ "[]" `fun0` ([] :: [a]), + ":" `fun2` ((:) :: a -> [a] -> [a]) + ] lists :: forall a. Var Ord a => a -> [Sig] lists a = - [ - -- Names to print arbitrary variables + [ -- Names to print arbitrary variables funs', funvars', vars', - -- Ambient definitions listCons a, - -- Expressions to deduce properties of - "sort" `fun1` (sort :: [a] -> [a]), - "map" `fun2` (map :: (a -> a) -> [a] -> [a]), - "id" `fun1` (id :: [a] -> [a]), - "reverse" `fun1` (reverse :: [a] -> [a]), - "minimum" `fun1` (minimum :: [a] -> a), - "length" `fun1` (length :: [a] -> Int), - "++" `fun2` ((++) :: [a] -> [a] -> [a]) + "sort" `fun1` (sort :: [a] -> [a]), + "map" `fun2` (map :: (a -> a) -> [a] -> [a]), + "id" `fun1` (id :: [a] -> [a]), + "reverse" `fun1` (reverse :: [a] -> [a]), + "minimum" `fun1` (minimum :: [a] -> a), + "length" `fun1` (length :: [a] -> Int), + "++" `fun2` ((++) :: [a] -> [a] -> [a]) ] - where - funs' = funs (undefined :: a) + funs' = funs (undefined :: a) funvars' = vars ["f", "g", "h"] (undefined :: a -> a) - vars' = ["xs", "ys", "zs"] `vars` (undefined :: [a]) - + vars' = ["xs", "ys", "zs"] `vars` (undefined :: [a]) tvar :: A tvar = undefined diff --git a/src/15-testing/stack.yaml b/src/15-testing/stack.yaml index d1bcc2f..765dbfa 100644 --- a/src/15-testing/stack.yaml +++ b/src/15-testing/stack.yaml @@ -1,32 +1,8 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md - -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-4.2 - -# Local packages, usually specified by relative directory name +resolver: lts-14.20 packages: - '.' - -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) -extra-deps: [] - -# Override default flag values for local packages and extra-deps +extra-deps: +- quickspec-2.1.2 +- twee-lib-2.1.5 flags: {} - -# Extra package databases containing global packages extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] diff --git a/src/ci b/src/ci index 80c0ffb..224de6a 100755 --- a/src/ci +++ b/src/ci @@ -54,6 +54,10 @@ echo -n "14-interpreters .. " (cd 14-interpreters && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "15-testing .. " +(cd 15-testing && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 0c52c01377a1f384373eae43ab3fb5485783adff Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 16:44:52 +0000 Subject: [PATCH 08/45] Chapter 16 CI --- src/16-type-families/ci | 15 ++++++ src/16-type-families/constraintkinds.hs | 9 ++-- src/16-type-families/example.cabal | 16 +++++++ src/16-type-families/mono.hs | 63 ------------------------- src/16-type-families/roles.hs | 8 ++-- src/16-type-families/stack.yaml | 6 +++ src/ci | 4 ++ 7 files changed, 52 insertions(+), 69 deletions(-) create mode 100755 src/16-type-families/ci create mode 100644 src/16-type-families/example.cabal delete mode 100644 src/16-type-families/mono.hs create mode 100644 src/16-type-families/stack.yaml diff --git a/src/16-type-families/ci b/src/16-type-families/ci new file mode 100755 index 0000000..a5bc7d5 --- /dev/null +++ b/src/16-type-families/ci @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive constraintkinds.hs +stack exec ghc -- -e ":q" --interactive datafamily.hs +stack exec ghc -- -e ":q" --interactive dict.hs +stack exec ghc -- -e ":q" --interactive family_nat_operators.hs +stack exec ghc -- -e ":q" --interactive family_type.hs +stack exec ghc -- -e ":q" --interactive fundeps.hs +stack exec ghc -- -e ":q" --interactive mparam.hs +stack exec ghc -- -e ":q" --interactive mparam_fun.hs +stack exec ghc -- -e ":q" --interactive noempty.hs +stack exec ghc -- -e ":q" --interactive proof.hs +stack exec ghc -- -e ":q" --interactive role_infer.hs +#stack exec ghc -- -e ":q" --interactive roles.hs diff --git a/src/16-type-families/constraintkinds.hs b/src/16-type-families/constraintkinds.hs index fa40385..d071d35 100644 --- a/src/16-type-families/constraintkinds.hs +++ b/src/16-type-families/constraintkinds.hs @@ -1,12 +1,15 @@ -{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE ConstrainedClassMethods #-} {-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE TypeFamilies #-} -import GHC.Exts (Constraint) -import Data.Hashable import Data.HashSet +import Data.Hashable +import GHC.Exts (Constraint) type family Con a :: Constraint + type instance Con [a] = (Ord a, Eq a) + type instance Con (HashSet a) = (Hashable a) class Sized a where diff --git a/src/16-type-families/example.cabal b/src/16-type-families/example.cabal new file mode 100644 index 0000000..f491715 --- /dev/null +++ b/src/16-type-families/example.cabal @@ -0,0 +1,16 @@ +name: example +version: 0.1 +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +copyright: 2016 Stephen Diehl +category: Documentation +build-type: Simple +cabal-version: >=1.10 +tested-with: GHC == 7.6.3 + +library + + build-depends: + base >= 4.6 && <4.14 + + default-language: Haskell2010 diff --git a/src/16-type-families/mono.hs b/src/16-type-families/mono.hs deleted file mode 100644 index 06a0ce0..0000000 --- a/src/16-type-families/mono.hs +++ /dev/null @@ -1,63 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE OverloadedStrings #-} - -import Data.Text -import Data.Char -import Data.Monoid -import Data.MonoTraversable -import Control.Applicative - -bs :: Text -bs = "Hello Haskell." - -shift :: Text -shift = omap (chr . (+1) . ord) bs --- "Ifmmp!Ibtlfmm/" - -backwards :: [Char] -backwards = ofoldl' (flip (:)) "" bs --- ".lleksaH olleH" - - -data MyMonoType = MNil | MCons Int MyMonoType deriving Show - -type instance Element MyMonoType = Int - -instance MonoFunctor MyMonoType where - omap f MNil = MNil - omap f (MCons x xs) = f x `MCons` omap f xs - -instance MonoFoldable MyMonoType where - ofoldMap f = ofoldr (mappend . f) mempty - ofoldr = mfoldr - ofoldl' = mfoldl' - ofoldr1Ex f = ofoldr1Ex f . mtoList - ofoldl1Ex' f = ofoldl1Ex' f . mtoList - -instance MonoTraversable MyMonoType where - omapM f xs = mapM f (mtoList xs) >>= return . mfromList - otraverse f = ofoldr acons (pure MNil) - where acons x ys = MCons <$> f x <*> ys - -mtoList :: MyMonoType -> [Int] -mtoList (MNil) = [] -mtoList (MCons x xs) = x : (mtoList xs) - -mfromList :: [Int] -> MyMonoType -mfromList [] = MNil -mfromList (x:xs) = MCons x (mfromList xs) - -mfoldr :: (Int -> a -> a) -> a -> MyMonoType -> a -mfoldr f z MNil = z -mfoldr f z (MCons x xs) = f x (mfoldr f z xs) - -mfoldl' :: (a -> Int -> a) -> a -> MyMonoType -> a -mfoldl' f z MNil = z -mfoldl' f z (MCons x xs) = let z' = z `f` x - in seq z' $ mfoldl' f z' xs - -ex1 :: Int -ex1 = mfoldl' (+) 0 (mfromList [1..25]) - -ex2 :: MyMonoType -ex2 = omap (+1) (mfromList [1..25]) diff --git a/src/16-type-families/roles.hs b/src/16-type-families/roles.hs index 1bc2c60..f8fabb2 100644 --- a/src/16-type-families/roles.hs +++ b/src/16-type-families/roles.hs @@ -1,11 +1,13 @@ -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TypeFamilies #-} -newtype Age = MkAge { unAge :: Int } +newtype Age = MkAge {unAge :: Int} type family Inspect x + type instance Inspect Age = Int + type instance Inspect Int = Bool class Boom a where diff --git a/src/16-type-families/stack.yaml b/src/16-type-families/stack.yaml new file mode 100644 index 0000000..f0eb25e --- /dev/null +++ b/src/16-type-families/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-14.20 +packages: +- '.' +extra-deps: [] +flags: {} +extra-package-dbs: [] diff --git a/src/ci b/src/ci index 224de6a..ec34ca5 100755 --- a/src/ci +++ b/src/ci @@ -58,6 +58,10 @@ echo -n "15-testing .. " (cd 15-testing && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "16-type-families .. " +(cd 16-type-families && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From f3d36308061ad688624a0a6a9cf3f3c8df7810f0 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 17:02:26 +0000 Subject: [PATCH 09/45] Fix build for Chapter 18 --- src/18-generics/example.cabal | 31 +++++++++++++++---------------- src/18-generics/stack.yaml | 28 +--------------------------- src/18-generics/syb.hs | 29 ----------------------------- 3 files changed, 16 insertions(+), 72 deletions(-) delete mode 100644 src/18-generics/syb.hs diff --git a/src/18-generics/example.cabal b/src/18-generics/example.cabal index 88c5ec9..4919b09 100644 --- a/src/18-generics/example.cabal +++ b/src/18-generics/example.cabal @@ -1,17 +1,16 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2016 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 -tested-with: GHC == 7.6.3 +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - - build-depends: - syb >= 0.6 && <0.7, - base >= 4.6 && <4.10 - - default-language: Haskell2010 +library + default-language: Haskell2010 + build-depends: + base >=4.6 && <4.14 + , cereal >=0.5.8.1 && <0.6 + , hashable >=1.2.0.0 && <1.4 + , uniplate >=1.6.12 && <1.7 diff --git a/src/18-generics/stack.yaml b/src/18-generics/stack.yaml index d1bcc2f..f0eb25e 100644 --- a/src/18-generics/stack.yaml +++ b/src/18-generics/stack.yaml @@ -1,32 +1,6 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md - -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-4.2 - -# Local packages, usually specified by relative directory name +resolver: lts-14.20 packages: - '.' - -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: [] - -# Override default flag values for local packages and extra-deps flags: {} - -# Extra package databases containing global packages extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] diff --git a/src/18-generics/syb.hs b/src/18-generics/syb.hs deleted file mode 100644 index d2f0aaa..0000000 --- a/src/18-generics/syb.hs +++ /dev/null @@ -1,29 +0,0 @@ -{-# LANGUAGE DeriveDataTypeable #-} - -import Data.Data -import Data.Typeable -import Data.Generics.Schemes -import Data.Generics.Aliases (mkT, extT) - -data MyTuple a = MyTuple a Float - deriving (Data, Typeable, Show) - -exampleT :: Data a => MyTuple a -> MyTuple a -exampleT = everywhere (mkT go1 `extT` go2) - where - go1 :: Int -> Int - go1 x = succ x - - go2 :: Float -> Float - go2 x = succ x - -findFloat :: Data x => x -> Maybe Float -findFloat = gfindtype - -main :: IO () -main = do - let term = MyTuple (MyTuple (1 :: Int) 2.0) 3.0 - print (exampleT term) - print (gsize term) - print (findFloat term) - print (listify ((>0) :: (Int -> Bool)) term) From b8166a93ec525252b338c6c52b407e541ac3fbe7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 17:27:25 +0000 Subject: [PATCH 10/45] Install libraries --- src/06-prelude/ci | 1 + src/07-text-bytestring/ci | 1 + 2 files changed, 2 insertions(+) diff --git a/src/06-prelude/ci b/src/06-prelude/ci index 75ff230..1bb17bf 100755 --- a/src/06-prelude/ci +++ b/src/06-prelude/ci @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive foldable_traversable.hs stack exec ghc -- -e ":q" --interactive split.hs diff --git a/src/07-text-bytestring/ci b/src/07-text-bytestring/ci index fed4957..3f38849 100755 --- a/src/07-text-bytestring/ci +++ b/src/07-text-bytestring/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive builder.hs stack exec ghc -- -e ":q" --interactive bytestring.hs #stack exec ghc -- -e ":q" --interactive overloadedlist.hs From 37505e365bb0c565d30edea118b92305a5596ed4 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 17:34:07 +0000 Subject: [PATCH 11/45] Stack build on all CI scripts --- src/09-errors/ci | 1 + src/10-advanced-monads/ci | 1 + src/11-quantification/ci | 1 + 3 files changed, 3 insertions(+) diff --git a/src/09-errors/ci b/src/09-errors/ci index fe4a7a6..1a74aa0 100755 --- a/src/09-errors/ci +++ b/src/09-errors/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive either.hs #stack exec ghc -- -e ":q" --interactive either_impl.hs stack exec ghc -- -e ":q" --interactive errors.hs diff --git a/src/10-advanced-monads/ci b/src/10-advanced-monads/ci index c5eb33a..68d851c 100755 --- a/src/10-advanced-monads/ci +++ b/src/10-advanced-monads/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive base.hs stack exec ghc -- -e ":q" --interactive cont.hs #stack exec ghc -- -e ":q" --interactive cont_impl.hs diff --git a/src/11-quantification/ci b/src/11-quantification/ci index 219b4fc..5ea598c 100755 --- a/src/11-quantification/ci +++ b/src/11-quantification/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive existential.hs stack exec ghc -- -e ":q" --interactive impredicative.hs #stack exec ghc -- -e ":q" --interactive rankn.hs From 8f6629ea237752c2c521be0da87f65a9bb9f119d Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 19 Feb 2020 17:47:58 +0000 Subject: [PATCH 12/45] Add free dependency --- src/10-advanced-monads/example.cabal | 3 ++- src/10-advanced-monads/free_dsl.hs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/10-advanced-monads/example.cabal b/src/10-advanced-monads/example.cabal index 3e0d944..4945650 100644 --- a/src/10-advanced-monads/example.cabal +++ b/src/10-advanced-monads/example.cabal @@ -17,6 +17,7 @@ library mtl >= 2.2 && <2.3, transformers-base >= 0.4 && <0.5, monad-control >= 1.0 && <1.1, - lifted-base >= 0.2 && <0.3 + lifted-base >= 0.2 && <0.3, + free >= 5.1 && <5.2 default-language: Haskell2010 diff --git a/src/10-advanced-monads/free_dsl.hs b/src/10-advanced-monads/free_dsl.hs index a92929a..618576b 100644 --- a/src/10-advanced-monads/free_dsl.hs +++ b/src/10-advanced-monads/free_dsl.hs @@ -1,13 +1,13 @@ {-# LANGUAGE DeriveFunctor #-} -import System.Exit import Control.Monad.Free +import System.Exit data Interaction x = Puts String x | Gets (Char -> x) | Exit - deriving Functor + deriving (Functor) type IOFree a = Free Interaction a @@ -32,8 +32,8 @@ interp :: IOFree a -> IO a interp (Pure r) = return r interp (Free x) = case x of Puts s t -> putStrLn s >> interp t - Gets f -> getChar >>= interp . f - Exit -> exitSuccess + Gets f -> getChar >>= interp . f + Exit -> exitSuccess echo :: IOFree () echo = do From e21ee8658c76cb759005e87047b2d4383ca5fc92 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 10:52:09 +0000 Subject: [PATCH 13/45] Chapter 17 CI --- src/17-promotion/ci | 24 ++++++++++++++++++++++++ src/17-promotion/errors.hs | 14 ++++++++------ src/17-promotion/example.cabal | 13 +++++++++++++ src/17-promotion/nonempty.hs | 8 ++++---- src/17-promotion/stack.yaml | 6 ++++++ src/ci | 4 ++++ 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100755 src/17-promotion/ci create mode 100644 src/17-promotion/example.cabal create mode 100644 src/17-promotion/stack.yaml diff --git a/src/17-promotion/ci b/src/17-promotion/ci new file mode 100755 index 0000000..2d458cd --- /dev/null +++ b/src/17-promotion/ci @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive closed_typefamily.hs +stack exec ghc -- -e ":q" --interactive constraint_list.hs +stack exec ghc -- -e ":q" --interactive countargs.hs +stack exec ghc -- -e ":q" --interactive datakinds.hs +#stack exec ghc -- -e ":q" --interactive errors.hs +#stack exec ghc -- -e ":q" --interactive errors_dsl.hs +stack exec ghc -- -e ":q" --interactive hasfield.hs +stack exec ghc -- -e ":q" --interactive hlist.hs +stack exec ghc -- -e ":q" --interactive kindpoly.hs +#stack exec ghc -- -e ":q" --interactive nonempty.hs +stack exec ghc -- -e ":q" --interactive reverse.hs +stack exec ghc -- -e ":q" --interactive reverse_nat.hs +stack exec ghc -- -e ":q" --interactive singleton.hs +stack exec ghc -- -e ":q" --interactive singleton_class.hs +stack exec ghc -- -e ":q" --interactive type_equality.hs +stack exec ghc -- -e ":q" --interactive typefamily.hs +stack exec ghc -- -e ":q" --interactive typelevel_fields.hs +stack exec ghc -- -e ":q" --interactive typelevel_strings.hs +stack exec ghc -- -e ":q" --interactive typemap.hs +stack exec ghc -- -e ":q" --interactive typenat.hs +stack exec ghc -- -e ":q" --interactive typenat_cmp.hs diff --git a/src/17-promotion/errors.hs b/src/17-promotion/errors.hs index aa42e3f..bfb975b 100644 --- a/src/17-promotion/errors.hs +++ b/src/17-promotion/errors.hs @@ -4,14 +4,16 @@ import GHC.TypeLits -instance - -- Error Message - TypeError (Text "Equality is not defined for functions" - :$$: - (ShowType a :<>: Text " -> " :<>: ShowType b)) +instance-- Error Message + TypeError + ( Text "Equality is not defined for functions" + :$$: (ShowType a :<>: Text " -> " :<>: ShowType b) + ) => -- Instance head - => Eq (a -> b) where (==) = undefined + Eq (a -> b) + where + (==) = undefined -- Fail when we try to equate two functions example = id == id diff --git a/src/17-promotion/example.cabal b/src/17-promotion/example.cabal new file mode 100644 index 0000000..6c2b2e5 --- /dev/null +++ b/src/17-promotion/example.cabal @@ -0,0 +1,13 @@ +name: example +version: 0.1 +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +copyright: 2020 Stephen Diehl +category: Documentation +build-type: Simple +cabal-version: >=1.10 + +library + default-language: Haskell2010 + build-depends: + base >= 4.6 && <4.14 diff --git a/src/17-promotion/nonempty.hs b/src/17-promotion/nonempty.hs index c53ef1f..a805b54 100644 --- a/src/17-promotion/nonempty.hs +++ b/src/17-promotion/nonempty.hs @@ -1,13 +1,13 @@ -{-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} data Size = Empty | NonEmpty data List a b where - Nil :: List Empty a + Nil :: List Empty a Cons :: a -> List b a -> List NonEmpty a head' :: List NonEmpty a -> a diff --git a/src/17-promotion/stack.yaml b/src/17-promotion/stack.yaml new file mode 100644 index 0000000..f0eb25e --- /dev/null +++ b/src/17-promotion/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-14.20 +packages: +- '.' +extra-deps: [] +flags: {} +extra-package-dbs: [] diff --git a/src/ci b/src/ci index ec34ca5..5ed5dc8 100755 --- a/src/ci +++ b/src/ci @@ -62,6 +62,10 @@ echo -n "16-type-families .. " (cd 16-type-families && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "17-promotion .. " +(cd 17-promotion && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 541c3e0b62c7807c606404865e40d169488958c7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 11:03:55 +0000 Subject: [PATCH 14/45] Fix links --- cabal.project | 1 + tutorial.md | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 cabal.project diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..e6fdbad --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/tutorial.md b/tutorial.md index 1e0f594..48cf86c 100644 --- a/tutorial.md +++ b/tutorial.md @@ -2767,7 +2767,7 @@ f = let x = x in x Examples of actual Haskell code that use this looping syntax live in the source code of the [GHC.Prim](https://hackage.haskell.org/package/ghc-prim-0.4.0.0/docs/GHC-Prim.html) module. These bottoms exist because the operations [cannot be defined in native -Haskell](https://downloads.haskell.org/~ghc/7.10.3/docs/html/users_guide/primitives.html). +Haskell](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/glasgow_exts.html#unboxed-types-and-primitive-operations). Such operations are baked into the compiler at a very low level. However, this module exists so that [Haddock](#haddock) can generate documentation for these primitive operations, while the looping syntax serves as a placeholder for the @@ -2898,7 +2898,7 @@ A.hs:3:1: The ``-Wall`` or ``-fwarn-incomplete-patterns`` flag can also be added on a per-module basis by using the ``OPTIONS_GHC`` -[pragma](https://downloads.haskell.org/~ghc/7.10.3/docs/html/users_guide/pragmas.html). +[pragma](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/glasgow_exts.html#rewrite-rules). ```haskell {-# OPTIONS_GHC -Wall #-} @@ -5134,7 +5134,7 @@ The golden source of truth for language extensions is the official GHC user's guide which contains a plethora of information on the details of these extensions. -See: [GHC Extension Reference](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/lang.html) +See: [GHC Extension Reference](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/lang.html) Extension Dependencies ---------------------- @@ -5146,7 +5146,7 @@ extensions and which sets are implied. Extension Implies ------------------------- --------------------------------------- TypeFamilyDependencies TypeFamilies -TypeInType PolyKinds DataKinds KindSignatures +TypeInType PolyKinds, DataKinds, KindSignatures PolyKinds KindSignatures ScopedTypeVariables ExplicitForAll RankNTypes ExplicitForAll @@ -5157,15 +5157,15 @@ RebindableSyntax NoImplicitPrelude TypeOperators ExplicitNamespaces LiberalTypeSynonyms ExplicitForAll ExistentialQuantification ExplicitForAll -GADTs MonoLocalBinds GADTSyntax +GADTs MonoLocalBinds, GADTSyntax DuplicateRecordFields DisambiguateRecordFields RecordWildCards DisambiguateRecordFields -DeriveTraversable DeriveFoldable DeriveFunctor +DeriveTraversable DeriveFoldable, DeriveFunctor MultiParamTypeClasses ConstrainedClassMethods DerivingVia DerivingStrategies FunctionalDependencies MultiParamTypeClasses FlexibleInstances TypeSynonymInstances -TypeFamilies MonoLocalBinds KindSignatures ExplicitNamespaces +TypeFamilies MonoLocalBinds, KindSignatures, ExplicitNamespaces IncoherentInstances OverlappingInstances The Benign From 6d0d5b5b47d285a1f0bc7468d3938267e20cd5f7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 11:40:10 +0000 Subject: [PATCH 15/45] Chapter 18 CI --- src/18-generics/ci | 13 +++++++++++++ src/18-generics/example.cabal | 27 ++++++++++++--------------- src/18-generics/generics.hs | 17 ++++++++++++----- src/ci | 4 ++++ 4 files changed, 41 insertions(+), 20 deletions(-) create mode 100755 src/18-generics/ci diff --git a/src/18-generics/ci b/src/18-generics/ci new file mode 100755 index 0000000..a7c3b9a --- /dev/null +++ b/src/18-generics/ci @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive biplate.hs +stack exec ghc -- -e ":q" --interactive cereal.hs +stack exec ghc -- -e ":q" --interactive data.hs +stack exec ghc -- -e ":q" --interactive derive_aeson.hs +stack exec ghc -- -e ":q" --interactive dynamic.hs +stack exec ghc -- -e ":q" --interactive generic_impl.hs +stack exec ghc -- -e ":q" --interactive generics.hs +stack exec ghc -- -e ":q" --interactive hashable.hs +stack exec ghc -- -e ":q" --interactive typeable.hs +stack exec ghc -- -e ":q" --interactive uniplate.hs diff --git a/src/18-generics/example.cabal b/src/18-generics/example.cabal index 4919b09..6c2b2e5 100644 --- a/src/18-generics/example.cabal +++ b/src/18-generics/example.cabal @@ -1,16 +1,13 @@ -cabal-version: >=1.10 -name: example -version: 0.1 -copyright: 2020 Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -author: Stephen Diehl -category: Documentation -build-type: Simple +name: example +version: 0.1 +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +copyright: 2020 Stephen Diehl +category: Documentation +build-type: Simple +cabal-version: >=1.10 -library - default-language: Haskell2010 - build-depends: - base >=4.6 && <4.14 - , cereal >=0.5.8.1 && <0.6 - , hashable >=1.2.0.0 && <1.4 - , uniplate >=1.6.12 && <1.7 +library + default-language: Haskell2010 + build-depends: + base >= 4.6 && <4.14 diff --git a/src/18-generics/generics.hs b/src/18-generics/generics.hs index f3acd0c..edcf293 100644 --- a/src/18-generics/generics.hs +++ b/src/18-generics/generics.hs @@ -1,5 +1,6 @@ -{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} import GHC.Generics @@ -8,7 +9,12 @@ data Animal | Cat instance Generic Animal where - type Rep Animal = D1 T_Animal ((C1 C_Dog U1) :+: (C1 C_Cat U1)) + type + Rep Animal = + D1 ( 'MetaData "Animal" "Main" "main" 'False ) + ( C1 ( 'MetaCons "Dog" 'PrefixI 'False) + U1 :+: C1 ( 'MetaCons "Cat" 'PrefixI 'False) U1 + ) from Dog = M1 (L1 (M1 U1)) from Cat = M1 (R1 (M1 U1)) @@ -16,13 +22,14 @@ instance Generic Animal where to (M1 (L1 (M1 U1))) = Dog to (M1 (R1 (M1 U1))) = Cat -data T_Animal -data C_Dog -data C_Cat +data T_Animal -- Animal type +data C_Dog -- Dog Constructor +data C_Cat -- Cat Constructor instance Datatype T_Animal where datatypeName _ = "Animal" moduleName _ = "Main" + packageName _ = "main" instance Constructor C_Dog where conName _ = "Dog" diff --git a/src/ci b/src/ci index 5ed5dc8..52fc4e3 100755 --- a/src/ci +++ b/src/ci @@ -66,6 +66,10 @@ echo -n "17-promotion .. " (cd 17-promotion && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "18-generics .. " +(cd 18-generics && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 0ac69afa3319c6a080d49661f894fa592ccf742f Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 11:54:26 +0000 Subject: [PATCH 16/45] Chapter 19 CI --- cabal.project | 1 - src/19-numbers/ci | 10 ++++++++++ src/19-numbers/example.cabal | 16 +++++++--------- src/ci | 4 ++++ 4 files changed, 21 insertions(+), 10 deletions(-) delete mode 100644 cabal.project create mode 100755 src/19-numbers/ci diff --git a/cabal.project b/cabal.project deleted file mode 100644 index e6fdbad..0000000 --- a/cabal.project +++ /dev/null @@ -1 +0,0 @@ -packages: . diff --git a/src/19-numbers/ci b/src/19-numbers/ci new file mode 100755 index 0000000..b8b18b7 --- /dev/null +++ b/src/19-numbers/ci @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive arithmoi.hs +stack exec ghc -- -e ":q" --interactive creal.hs +stack exec ghc -- -e ":q" --interactive polynomial.hs +stack exec ghc -- -e ":q" --interactive puzzle.hs +stack exec ghc -- -e ":q" --interactive scientific.hs +stack exec ghc -- -e ":q" --interactive stats.hs diff --git a/src/19-numbers/example.cabal b/src/19-numbers/example.cabal index ccd7d89..7d4b80f 100644 --- a/src/19-numbers/example.cabal +++ b/src/19-numbers/example.cabal @@ -1,21 +1,19 @@ name: example -version: 0.1 +version: 0.1.0.0 author: Stephen Diehl maintainer: stephen.m.diehl@gmail.com copyright: 2016 Stephen Diehl category: Documentation build-type: Simple cabal-version: >=1.10 -tested-with: GHC == 7.6.3 library - + default-language: Haskell2010 build-depends: base >= 4.10 && <4.14, - poly >= 0.3 && <0.4, - scientific >= 0.3 && <0.4, - sbv >= 8.5 && <8.6, + poly >= 0.3 && <0.4, + scientific >= 0.3 && <0.4, + sbv >= 8.5 && <8.6, statistics >= 0.15 && <0.16, - arithmoi >= 0.9 && <0.11 - - default-language: Haskell2010 + arithmoi >= 0.9 && <0.11, + numbers -any diff --git a/src/ci b/src/ci index 52fc4e3..ab54b65 100755 --- a/src/ci +++ b/src/ci @@ -70,6 +70,10 @@ echo -n "18-generics .. " (cd 18-generics && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "19-numbers .. " +(cd 19-numbers && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 3325bcd8741775ed4b999b060c9562df9067c3c0 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 12:15:05 +0000 Subject: [PATCH 17/45] Fix links --- src/20-data-structures/hblas.hs | 16 ++++---- src/20-data-structures/matrix_index.hs | 52 -------------------------- tutorial.md | 8 ++-- 3 files changed, 11 insertions(+), 65 deletions(-) delete mode 100644 src/20-data-structures/matrix_index.hs diff --git a/src/20-data-structures/hblas.hs b/src/20-data-structures/hblas.hs index 5e54a49..ba9358e 100644 --- a/src/20-data-structures/hblas.hs +++ b/src/20-data-structures/hblas.hs @@ -4,15 +4,13 @@ import Numerical.HBLAS.MatrixTypes -- Generate the constant mutable square matrix of the given type and dimensions. constMatrix :: Storable a => Int -> a -> IO (IODenseMatrix Row a) -constMatrix n k = generateMutableDenseMatrix SRow (n,n) (const k) +constMatrix n k = generateMutableDenseMatrix SRow (n, n) (const k) example_dgemm :: IO () example_dgemm = do - left <- constMatrix 2 (2 :: Double) - right <- constMatrix 2 (3 :: Double) - out <- constMatrix 2 (0 :: Double) - - dgemm NoTranspose NoTranspose 1.0 1.0 left right out - - resulting <- mutableVectorToList $ _bufferDenMutMat out - print resulting + left <- constMatrix 2 (2 :: Double) + right <- constMatrix 2 (3 :: Double) + out <- constMatrix 2 (0 :: Double) + dgemm NoTranspose NoTranspose 1.0 1.0 left right out + resulting <- mutableVectorToList $ _bufferDenMutMat out + print resulting diff --git a/src/20-data-structures/matrix_index.hs b/src/20-data-structures/matrix_index.hs deleted file mode 100644 index 53927a7..0000000 --- a/src/20-data-structures/matrix_index.hs +++ /dev/null @@ -1,52 +0,0 @@ -import qualified Data.Vector as V - -data Order = RowMajor | ColMajor - -rowMajor :: [Int] -> [Int] -rowMajor = scanr (*) 1 . tail - -colMajor :: [Int] -> [Int] -colMajor = init . scanl (*) 1 - -data Matrix a = Matrix - { _dims :: [Int] - , _elts :: V.Vector a - , _order :: Order - } - -fromList :: [Int] -> Order -> [a] -> Matrix a -fromList sh order elts = - if product sh == length elts - then Matrix sh (V.fromList elts) order - else error "dimensions don't match" - -indexTo :: [Int] -> Matrix a -> a -indexTo ix mat = boundsCheck offset - where - boundsCheck n = - if 0 <= n && n < V.length (_elts mat) - then V.unsafeIndex (_elts mat) offset - else error "out of bounds" - ordering = case _order mat of - RowMajor -> rowMajor - ColMajor -> colMajor - offset = sum $ zipWith (*) ix (ordering (_dims mat)) - -matrix :: Order -> Matrix Int -matrix order = fromList [4,4] order [1..16] - -ex1 :: [Int] -ex1 = rowMajor [1,2,3,4] --- [24,12,4,1] - -ex2 :: [Int] -ex2 = colMajor [1,2,3,4] --- [1,1,2,6] - -ex3 :: Int -ex3 = indexTo [1,3] (matrix RowMajor) --- 8 - -ex4 :: Int -ex4 = indexTo [1,3] (matrix ColMajor) --- 14 diff --git a/tutorial.md b/tutorial.md index 48cf86c..db4bfb0 100644 --- a/tutorial.md +++ b/tutorial.md @@ -870,10 +870,10 @@ the default import many libraries these days do not use the standard prelude instead choosing to roll a custom one on a per-project basis or to use a off-the shelf prelude from Hackage. -The Prelude contains common datatype and classes such as [List], -[Monad](#monads), [Maybe] and most simple associated functions for manipulating -these structures. These are the most foundational programming constructs in -Haskell. +The Prelude contains common datatype and classes such as [List](#lists), +[Monad](#monads), [Maybe](#algebraic-datatypes) and most simple associated +functions for manipulating these structures. These are the most foundational +programming constructs in Haskell. Modern Haskell -------------- From 1d2cdc2040bbc3d65f36ff61004776502c88d6e7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 12:21:21 +0000 Subject: [PATCH 18/45] Chapter 20 CI --- src/20-data-structures/ci | 15 +++++++++++++++ src/20-data-structures/example.cabal | 19 +++++++++++++++++++ src/20-data-structures/stack.yaml | 3 +++ src/ci | 4 ++++ 4 files changed, 41 insertions(+) create mode 100755 src/20-data-structures/ci create mode 100644 src/20-data-structures/example.cabal create mode 100644 src/20-data-structures/stack.yaml diff --git a/src/20-data-structures/ci b/src/20-data-structures/ci new file mode 100755 index 0000000..50d39a9 --- /dev/null +++ b/src/20-data-structures/ci @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive dlist.hs +stack exec ghc -- -e ":q" --interactive graph.hs +stack exec ghc -- -e ":q" --interactive hashtables.hs +#stack exec ghc -- -e ":q" --interactive hblas.hs +stack exec ghc -- -e ":q" --interactive map.hs +stack exec ghc -- -e ":q" --interactive sequence.hs +stack exec ghc -- -e ":q" --interactive set.hs +stack exec ghc -- -e ":q" --interactive tree.hs +stack exec ghc -- -e ":q" --interactive unordered.hs +stack exec ghc -- -e ":q" --interactive vector.hs +stack exec ghc -- -e ":q" --interactive vector_mutable.hs diff --git a/src/20-data-structures/example.cabal b/src/20-data-structures/example.cabal new file mode 100644 index 0000000..227d9c5 --- /dev/null +++ b/src/20-data-structures/example.cabal @@ -0,0 +1,19 @@ +cabal-version: >=1.10 +name: example +version: 0.1.0.0 +copyright: 2016 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple + +library + default-language: Haskell2010 + build-depends: + base >=4.10 && <4.14 + , containers >=0.6.0.1 && <0.7 + , dlist >=0.8.0.7 && <0.9 + , hashtables >= 1.2 && <1.3 + , hblas >= 0.4 && <0.5 + , hmatrix >= 0.20 && <0.21 + , unordered-containers >=0.2.10.0 && <0.3 diff --git a/src/20-data-structures/stack.yaml b/src/20-data-structures/stack.yaml new file mode 100644 index 0000000..8fd4bcd --- /dev/null +++ b/src/20-data-structures/stack.yaml @@ -0,0 +1,3 @@ +resolver: lts-14.20 +extra-deps: + - hblas-0.4.0.1 diff --git a/src/ci b/src/ci index ab54b65..d4098ce 100755 --- a/src/ci +++ b/src/ci @@ -74,6 +74,10 @@ echo -n "19-numbers .. " (cd 19-numbers && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "20-data-structures .. " +(cd 20-data-structures && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 4a9073d68dde9ae317212c9fa7211a883b8c3baf Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 12:24:55 +0000 Subject: [PATCH 19/45] Chapter 21 FFI --- src/21-ffi/ci | 6 ++++++ src/21-ffi/example.cabal | 13 +++++++++++++ src/21-ffi/stack.yaml | 2 ++ src/ci | 4 ++++ 4 files changed, 25 insertions(+) create mode 100755 src/21-ffi/ci create mode 100644 src/21-ffi/example.cabal create mode 100644 src/21-ffi/stack.yaml diff --git a/src/21-ffi/ci b/src/21-ffi/ci new file mode 100755 index 0000000..409b54d --- /dev/null +++ b/src/21-ffi/ci @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive ffi.hs +stack exec ghc -- -e ":q" --interactive simple_ffi.hs diff --git a/src/21-ffi/example.cabal b/src/21-ffi/example.cabal new file mode 100644 index 0000000..e1901b1 --- /dev/null +++ b/src/21-ffi/example.cabal @@ -0,0 +1,13 @@ +cabal-version: >=1.10 +name: example +version: 0.1.0.0 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple + +library + default-language: Haskell2010 + build-depends: + base >=4.10 && <4.14 diff --git a/src/21-ffi/stack.yaml b/src/21-ffi/stack.yaml new file mode 100644 index 0000000..bee1b88 --- /dev/null +++ b/src/21-ffi/stack.yaml @@ -0,0 +1,2 @@ +resolver: lts-14.20 +extra-deps: [] diff --git a/src/ci b/src/ci index d4098ce..8525bd9 100755 --- a/src/ci +++ b/src/ci @@ -78,6 +78,10 @@ echo -n "20-data-structures .. " (cd 20-data-structures && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "21-ffi .. " +(cd 21-ffi && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 4b7df5603cc79cfffdd92b72b2bd94f156cbaea6 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 12:35:25 +0000 Subject: [PATCH 20/45] Chapter 22 CI --- src/22-concurrency/ci | 11 +++++++++++ src/22-concurrency/example.cabal | 14 ++++++++++++++ src/22-concurrency/par.hs | 12 +++++++----- src/22-concurrency/stack.yaml | 2 ++ src/ci | 4 ++++ 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100755 src/22-concurrency/ci create mode 100644 src/22-concurrency/example.cabal create mode 100644 src/22-concurrency/stack.yaml diff --git a/src/22-concurrency/ci b/src/22-concurrency/ci new file mode 100755 index 0000000..8256513 --- /dev/null +++ b/src/22-concurrency/ci @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive async.hs +stack exec ghc -- -e ":q" --interactive par.hs +stack exec ghc -- -e ":q" --interactive spark.hs +stack exec ghc -- -e ":q" --interactive sparks.hs +stack exec ghc -- -e ":q" --interactive stm.hs +stack exec ghc -- -e ":q" --interactive strategies.hs +stack exec ghc -- -e ":q" --interactive strategies_param.hs diff --git a/src/22-concurrency/example.cabal b/src/22-concurrency/example.cabal new file mode 100644 index 0000000..cf6aeb7 --- /dev/null +++ b/src/22-concurrency/example.cabal @@ -0,0 +1,14 @@ +cabal-version: >=1.10 +name: example +version: 0.1.0.0 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple + +library + default-language: Haskell2010 + build-depends: + base >=4.10 && <4.14, + monad-par >=0.3 && <0.4 diff --git a/src/22-concurrency/par.hs b/src/22-concurrency/par.hs index 14a274a..6e72bd4 100644 --- a/src/22-concurrency/par.hs +++ b/src/22-concurrency/par.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE NoMonadFailDesugaring #-} + import Control.Monad import Control.Monad.Par -f, g :: Int -> Int +f , g :: Int -> Int f x = x + 10 g x = x * 10 @@ -15,7 +17,7 @@ g x = x * 10 example1 :: Int -> (Int, Int) example1 x = runPar $ do - [a,b,c,d,e] <- replicateM 5 new + [a, b, c, d, e] <- replicateM 5 new fork (put a (f x)) fork (put b (g x)) a' <- get a @@ -30,13 +32,13 @@ example1 x = runPar $ do example2 :: [Int] example2 = runPar $ do - xs <- parMap (+1) [1..25] + xs <- parMap (+ 1) [1 .. 25] return xs -- foldr (+) 0 (map (^2) [1..xs]) example3 :: Int -> Int example3 n = runPar $ do let range = (InclusiveRange 1 n) - let mapper x = return (x^2) - let reducer x y = return (x+y) + let mapper x = return (x ^ 2) + let reducer x y = return (x + y) parMapReduceRangeThresh 10 range mapper reducer 0 diff --git a/src/22-concurrency/stack.yaml b/src/22-concurrency/stack.yaml new file mode 100644 index 0000000..bee1b88 --- /dev/null +++ b/src/22-concurrency/stack.yaml @@ -0,0 +1,2 @@ +resolver: lts-14.20 +extra-deps: [] diff --git a/src/ci b/src/ci index 8525bd9..ed4d29b 100755 --- a/src/ci +++ b/src/ci @@ -82,6 +82,10 @@ echo -n "21-ffi .. " (cd 21-ffi && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "22-concurrency .. " +(cd 22-concurrency && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 5ef27fb83c47c647c29b77f8abc565bb6a636e31 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 12:42:37 +0000 Subject: [PATCH 21/45] Flush README --- src/01-basics/README.md | 10 ---------- src/02-monads/README.md | 14 -------------- src/03-monad-transformers/README.md | 15 --------------- src/04-extensions/README.md | 13 ------------- src/05-laziness/README.md | 7 ------- src/06-prelude/README.md | 7 ------- src/07-text-bytestring/README.md | 11 ----------- src/08-applicatives/README.md | 7 ------- src/09-errors/README.md | 12 ------------ src/10-advanced-monads/README.md | 18 ------------------ src/11-quantification/README.md | 9 --------- src/13-lambda-calculus/README.md | 10 ---------- src/14-interpreters/README.md | 11 ----------- src/15-testing/README.md | 13 ------------- src/16-type-families/README.md | 18 ------------------ src/17-promotion/README.md | 25 ------------------------- src/18-generics/README.md | 15 --------------- src/19-numbers/README.md | 9 --------- src/20-data-structures/README.md | 17 ----------------- src/21-ffi/README.md | 10 ---------- src/22-concurrency/README.md | 12 ------------ src/23-graphics/README.md | 6 ------ src/24-parsing/README.md | 15 --------------- src/24-parsing/test.sh | 3 --- src/25-streaming/README.md | 11 ----------- src/26-data-formats/README.md | 13 ------------- src/27-web/README.md | 9 --------- src/28-databases/README.md | 8 -------- src/29-ghc/README.md | 16 ---------------- src/ci | 4 ++++ 30 files changed, 4 insertions(+), 344 deletions(-) delete mode 100644 src/01-basics/README.md delete mode 100644 src/02-monads/README.md delete mode 100644 src/03-monad-transformers/README.md delete mode 100644 src/04-extensions/README.md delete mode 100644 src/05-laziness/README.md delete mode 100644 src/06-prelude/README.md delete mode 100644 src/07-text-bytestring/README.md delete mode 100644 src/08-applicatives/README.md delete mode 100644 src/09-errors/README.md delete mode 100644 src/10-advanced-monads/README.md delete mode 100644 src/11-quantification/README.md delete mode 100644 src/13-lambda-calculus/README.md delete mode 100644 src/14-interpreters/README.md delete mode 100644 src/15-testing/README.md delete mode 100644 src/16-type-families/README.md delete mode 100644 src/17-promotion/README.md delete mode 100644 src/18-generics/README.md delete mode 100644 src/19-numbers/README.md delete mode 100644 src/20-data-structures/README.md delete mode 100644 src/21-ffi/README.md delete mode 100644 src/22-concurrency/README.md delete mode 100644 src/23-graphics/README.md delete mode 100644 src/24-parsing/README.md delete mode 100755 src/24-parsing/test.sh delete mode 100644 src/25-streaming/README.md delete mode 100644 src/26-data-formats/README.md delete mode 100644 src/27-web/README.md delete mode 100644 src/28-databases/README.md delete mode 100644 src/29-ghc/README.md diff --git a/src/01-basics/README.md b/src/01-basics/README.md deleted file mode 100644 index 754c24d..0000000 --- a/src/01-basics/README.md +++ /dev/null @@ -1,10 +0,0 @@ -Basics -====== - -```bash -$ stack exec ghci bottoms.hs -$ stack exec ghci defer.hs -$ stack exec ghci fail.hs -$ stack exec ghci stacktrace.hs -$ stack exec ghci trace.hs -``` diff --git a/src/02-monads/README.md b/src/02-monads/README.md deleted file mode 100644 index 104ae27..0000000 --- a/src/02-monads/README.md +++ /dev/null @@ -1,14 +0,0 @@ -Monads -====== - -```bash -$ stack exec ghci list.hs -$ stack exec ghci maybe.hs -$ stack exec ghci maybe_impl.hs -$ stack exec ghci reader.hs -$ stack exec ghci reader_impl.hs -$ stack exec ghci state.hs -$ stack exec ghci state_impl.hs -$ stack exec ghci writer.hs -$ stack exec ghci writer_impl.hs -``` diff --git a/src/03-monad-transformers/README.md b/src/03-monad-transformers/README.md deleted file mode 100644 index 0af34c6..0000000 --- a/src/03-monad-transformers/README.md +++ /dev/null @@ -1,15 +0,0 @@ -Monads -====== - -```bash -$ stach exec list.hs -$ stach exec list_impl.hs -$ stach exec maybe.hs -$ stach exec maybe_impl.hs -$ stach exec reader.hs -$ stach exec reader_impl.hs -$ stach exec state.hs -$ stach exec state_impl.hs -$ stach exec writer.hs -$ stach exec writer_impl.hs -``` diff --git a/src/04-extensions/README.md b/src/04-extensions/README.md deleted file mode 100644 index 1277342..0000000 --- a/src/04-extensions/README.md +++ /dev/null @@ -1,13 +0,0 @@ -Language Extensions -=================== - -```bash -$ stack exec ghci lambdacase.hs -$ stack exec ghci monomorphism.hs -$ stack exec ghci patterns.hs -$ stack exec ghci safe.hs -$ stack exec ghci views.hs -$ stack exec ghci wildcards.hs -$ stack exec ghci monomorphism.hs -$ stack exec ghci wildcards_update.hs -``` diff --git a/src/05-laziness/README.md b/src/05-laziness/README.md deleted file mode 100644 index 7a11f96..0000000 --- a/src/05-laziness/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Laziness -====== - -```bash -$ stach exec ghci lazy_patterns.hs -$ stach exec ghci nodiverge.hs -``` diff --git a/src/06-prelude/README.md b/src/06-prelude/README.md deleted file mode 100644 index db24b5c..0000000 --- a/src/06-prelude/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Prelude -======= - -```bash -$ stack exec ghci split.hs -$ stack exec ghci foldable_traversable.hs -``` diff --git a/src/07-text-bytestring/README.md b/src/07-text-bytestring/README.md deleted file mode 100644 index 7dfa378..0000000 --- a/src/07-text-bytestring/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Text/ ByteString -=== - -```bash -$ stack exec ghci builder.hs -$ stack exec ghci bytestring.hs -$ stack exec ghci convert.hs -$ stack exec ghci overloadedlist.hs -$ stack exec ghci printf.hs -$ stack exec ghci text.hs -``` diff --git a/src/08-applicatives/README.md b/src/08-applicatives/README.md deleted file mode 100644 index 43b501c..0000000 --- a/src/08-applicatives/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Applicative Functors -==================== - -```bash -$ stack exec ghci applicative.hs -$ stack exec ghci variadic.hs -``` diff --git a/src/09-errors/README.md b/src/09-errors/README.md deleted file mode 100644 index cf38288..0000000 --- a/src/09-errors/README.md +++ /dev/null @@ -1,12 +0,0 @@ -Language Extensions -=================== - -```bash -$ stack exec ghci either.hs -$ stack exec ghci either_impl.hs -$ stack exec ghci eithert.hs -$ stack exec ghci errors.hs -$ stack exec ghci exceptions.hs -$ stack exec ghci ioexception.hs -$ stack exec ghci spoon.hs -``` diff --git a/src/10-advanced-monads/README.md b/src/10-advanced-monads/README.md deleted file mode 100644 index 119dbee..0000000 --- a/src/10-advanced-monads/README.md +++ /dev/null @@ -1,18 +0,0 @@ -Advanced Monads -=============== - -```bash -$ stack exec ghci cont.hs -$ stack exec ghci cont_impl.hs -$ stack exec ghci free_dsl.hs -$ stack exec ghci free_impl.hs -$ stack exec ghci function.hs -$ stack exec ghci indexed.hs -$ stack exec ghci logict.hs -$ stack exec ghci mmorph.hs -$ stack exec ghci monadfix.hs -$ stack exec ghci monadplus.hs -$ stack exec ghci partiality.hs -$ stack exec ghci rws.hs -$ stack exec ghci st.hs -``` diff --git a/src/11-quantification/README.md b/src/11-quantification/README.md deleted file mode 100644 index 6e1eb02..0000000 --- a/src/11-quantification/README.md +++ /dev/null @@ -1,9 +0,0 @@ -Quantification -============== - -```bash -$ stack exec ghci universal.hs -$ stack exec ghci existential.hs -$ stack exec ghci impredicative.hs -$ stack exec ghci rankn.hs -``` diff --git a/src/13-lambda-calculus/README.md b/src/13-lambda-calculus/README.md deleted file mode 100644 index a041082..0000000 --- a/src/13-lambda-calculus/README.md +++ /dev/null @@ -1,10 +0,0 @@ -Lambda Calculus -=============== - -```bash -$ stack exec bash church_encoding.hs -$ stack exec bash church_list.hs -$ stack exec bash debruijn.hs -$ stack exec bash hoas.hs -$ stack exec bash phoas.hs -``` diff --git a/src/14-interpreters/README.md b/src/14-interpreters/README.md deleted file mode 100644 index 97bd735..0000000 --- a/src/14-interpreters/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Interpreters -============ - -```bash -$ stack exec ghci catamorphism.hs -$ stack exec ghci fext.hs -$ stack exec ghci final.hs -$ stack exec ghci initial.hs -$ stack exec ghci initial_interpreter.hs -$ stack exec ghci recursion_schemes.hs -``` diff --git a/src/15-testing/README.md b/src/15-testing/README.md deleted file mode 100644 index 2e05a0f..0000000 --- a/src/15-testing/README.md +++ /dev/null @@ -1,13 +0,0 @@ -Testing -======= - -```bash -$ stack exec ghci arbitrary.hs -$ stack exec ghci criterion.hs -$ stack exec ghci qcheck.hs -$ stack exec ghci quickspec.hs -$ stack exec ghci smallcheck.hs -$ stack exec ghci smallcheck_series.hs -$ stack exec ghci smallcheck_tree.hs -$ stack exec ghci tasty.hs -``` diff --git a/src/16-type-families/README.md b/src/16-type-families/README.md deleted file mode 100644 index 008e909..0000000 --- a/src/16-type-families/README.md +++ /dev/null @@ -1,18 +0,0 @@ -Type Families -============= - -```bash -$ stack exec ghci constraintkinds.hs -$ stack exec ghci datafamily.hs -$ stack exec ghci dict.hs -$ stack exec ghci family_nat_operators.hs -$ stack exec ghci family_type.hs -$ stack exec ghci fundeps.hs -$ stack exec ghci mono.hs -$ stack exec ghci mparam.hs -$ stack exec ghci mparam_fun.hs -$ stack exec ghci noempty.hs -$ stack exec ghci proof.hs -$ stack exec ghci role_infer.hs -$ stack exec ghci roles.hs -``` diff --git a/src/17-promotion/README.md b/src/17-promotion/README.md deleted file mode 100644 index d28d0d2..0000000 --- a/src/17-promotion/README.md +++ /dev/null @@ -1,25 +0,0 @@ -Promotion -========= - -```bash -$ stack exec ghci closed_typefamily.hs -$ stack exec ghci constraint_list.hs -$ stack exec ghci countargs.hs -$ stack exec ghci datakinds.hs -$ stack exec ghci errors.hs -$ stack exec ghci errors_dsl.hs -$ stack exec ghci hasfield.hs -$ stack exec ghci hlist.hs -$ stack exec ghci kindpoly.hs -$ stack exec ghci nonempty.hs -$ stack exec ghci reverse.hs -$ stack exec ghci reverse_nat.hs -$ stack exec ghci singleton.hs -$ stack exec ghci singleton_class.hs -$ stack exec ghci type_equality.hs -$ stack exec ghci typefamily.hs -$ stack exec ghci typelevel_fields.hs -$ stack exec ghci typemap.hs -$ stack exec ghci typenat.hs -$ stack exec ghci typenat_cmp.hs -``` diff --git a/src/18-generics/README.md b/src/18-generics/README.md deleted file mode 100644 index 8b8286a..0000000 --- a/src/18-generics/README.md +++ /dev/null @@ -1,15 +0,0 @@ -Generics -======== - -```bash -$ stack exec ghci biplate.hs -$ stack exec ghci cereal.hs -$ stack exec ghci data.hs -$ stack exec ghci derive_aeson.hs -$ stack exec ghci dynamic.hs -$ stack exec ghci generic_impl.hs -$ stack exec ghci generics.hs -$ stack exec ghci hashable.hs -$ stack exec ghci typeable.hs -$ stack exec ghci uniplate.hs -``` diff --git a/src/19-numbers/README.md b/src/19-numbers/README.md deleted file mode 100644 index 1a4592f..0000000 --- a/src/19-numbers/README.md +++ /dev/null @@ -1,9 +0,0 @@ -Numbers -======= - -```bash -$ stack exec ghci creal.hs -$ stack exec ghci puzzle.hs -$ stack exec ghci scientific.hs -$ stack exec ghci stats.hs -``` diff --git a/src/20-data-structures/README.md b/src/20-data-structures/README.md deleted file mode 100644 index 5c2b5e5..0000000 --- a/src/20-data-structures/README.md +++ /dev/null @@ -1,17 +0,0 @@ -Data Structures -=============== - -```bash -$ stack exec ghci dlist.hs -$ stack exec ghci graph.hs -$ stack exec ghci hashtables.hs -$ stack exec ghci hblas.hs -$ stack exec ghci map.hs -$ stack exec ghci matrix_index.hs -$ stack exec ghci sequence.hs -$ stack exec ghci set.hs -$ stack exec ghci tree.hs -$ stack exec ghci unordered.hs -$ stack exec ghci vector.hs -$ stack exec ghci vector_mutable.hs -``` diff --git a/src/21-ffi/README.md b/src/21-ffi/README.md deleted file mode 100644 index 0e55456..0000000 --- a/src/21-ffi/README.md +++ /dev/null @@ -1,10 +0,0 @@ -Foreign Function Interface -========================== - -XXX: include gcc invocation - -``` -$ stack exec ghci ffi.hs -$ stack exec ghci pointer_use.hs -$ stack exec ghci simple_ffi.hs -``` diff --git a/src/22-concurrency/README.md b/src/22-concurrency/README.md deleted file mode 100644 index 082f6dd..0000000 --- a/src/22-concurrency/README.md +++ /dev/null @@ -1,12 +0,0 @@ -Concurrency -=========== - -```bash -$ stack exec ghci async.hs -$ stack exec ghci par.hs -$ stack exec ghci spark.hs -$ stack exec ghci sparks.hs -$ stack exec ghci stm.hs -$ stack exec ghci strategies.hs -$ stack exec ghci strategies_param.hs -``` diff --git a/src/23-graphics/README.md b/src/23-graphics/README.md deleted file mode 100644 index 72006f0..0000000 --- a/src/23-graphics/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Graphics -======== - -```bash -$ stack exec ghci diagrams.hs -``` diff --git a/src/24-parsing/README.md b/src/24-parsing/README.md deleted file mode 100644 index d821115..0000000 --- a/src/24-parsing/README.md +++ /dev/null @@ -1,15 +0,0 @@ -Parsing -======= - -```bash - $ stack exec ghci attoparsec.hs - $ stack exec ghci attoparsec_lang.hs - $ stack exec ghci generics.hs - $ stack exec ghci lexer_text.hs - $ stack exec ghci optparse_applicative.hs - $ stack exec ghci parsec_applicative.hs - $ stack exec ghci parsec_operators.hs - $ stack exec ghci parser.hs - $ stack exec ghci simple_parser.hs - $ stack exec ghci configurator.hs -``` diff --git a/src/24-parsing/test.sh b/src/24-parsing/test.sh deleted file mode 100755 index fc09c78..0000000 --- a/src/24-parsing/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -for f in *.hs; do - echo ":quit" | stack exec ghci $f -done diff --git a/src/25-streaming/README.md b/src/25-streaming/README.md deleted file mode 100644 index 519f9fc..0000000 --- a/src/25-streaming/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Streaming -========= - -```bash -$ stack exec ghci conduit.hs -$ stack exec ghci lazyio.hs -$ stack exec ghci pipes.hs -$ stack exec ghci pipes_file.hs -$ stack exec ghci pipes_io.hs -$ stack exec ghci pipes_safe.hs - ``` diff --git a/src/26-data-formats/README.md b/src/26-data-formats/README.md deleted file mode 100644 index 6bf1948..0000000 --- a/src/26-data-formats/README.md +++ /dev/null @@ -1,13 +0,0 @@ -Data Formats -============ - -```bash -$ stack exec ghci aeson_custom.hs -$ stack exec ghci aeson_derive.hs -$ stack exec ghci aeson_structured.hs -$ stack exec ghci aeson_unstructured.hs -$ stack exec ghci cassava_structured.hs -$ stack exec ghci cassava_unstructured.hs -$ stack exec ghci stack.yaml -$ stack exec ghci yaml.hs -``` diff --git a/src/27-web/README.md b/src/27-web/README.md deleted file mode 100644 index 09db8ae..0000000 --- a/src/27-web/README.md +++ /dev/null @@ -1,9 +0,0 @@ -Web -=== - -```bash -$ stack exec ghci hastache.hs -$ stack exec ghci hastache_generic.hs -$ stack exec ghci blaze.hs -$ stack exec ghci blaze_instance.hs -``` diff --git a/src/28-databases/README.md b/src/28-databases/README.md deleted file mode 100644 index ffd0663..0000000 --- a/src/28-databases/README.md +++ /dev/null @@ -1,8 +0,0 @@ -Web -=== - -```bash -$ stack exec ghci acid.hs -$ stack exec ghci hedis.hs -$ stack exec ghci hedis_pubsub.hs -``` diff --git a/src/29-ghc/README.md b/src/29-ghc/README.md deleted file mode 100644 index 7bf9fd5..0000000 --- a/src/29-ghc/README.md +++ /dev/null @@ -1,16 +0,0 @@ -GHC -=== - -```bash -$ stack exec ghci closure_size.hs -$ stack exec ghci cmm_include.hs -$ stack exec ghci dictionaries.hs -$ stack exec ghci ekg.hs -$ stack exec ghci example.hs -$ stack exec ghci heapview.hs -$ stack exec ghci io_impl.hs -$ stack exec ghci monad_prim.hs -$ stack exec ghci prim.hs -$ stack exec ghci profile.hs -$ stack exec ghci specialize.hs -``` diff --git a/src/ci b/src/ci index ed4d29b..60116db 100755 --- a/src/ci +++ b/src/ci @@ -86,6 +86,10 @@ echo -n "22-concurrency .. " (cd 22-concurrency && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "24-parsing .. " +(cd 24-parsing && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" From 97f5c0665ab67b8dd168555b1cf3736543c98839 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 16:07:18 +0000 Subject: [PATCH 22/45] Fix page overflow --- README.md | 13 +++++++------ tutorial.md | 22 +++++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 29b2463..c84607c 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,17 @@ Git: d429c2e21b9636cffa27a8d4f063644b8bcecf1a Contributing ------------ -If you want to submit a fix for a typo or fix for code then just submit a pull -request, and I'm happy to recompile the resulting document. Edit the following -Markdown file which generates all other targets. +If you want to submit a fix for a typo or fix edit the following Markdown file +which generates all other targets. [tutorial.md](./tutorial.md) +Then submit a Pull Request on Github describing your change. + Source code is directly included from the `src` directory into the resulting -document by the preprocessor. To fix a change or include a new sample edit the -example source code directly. In addition add the new file to the `ci` script -inside of the folder so it is run in the continuous integration script. +document by the preprocessor. To include a new sample edit the example source +code directly. When adding a new Haskell file, add it to the `ci` script inside +of the folder so it is run in the continuous integration script. Source Code ----------- diff --git a/tutorial.md b/tutorial.md index db4bfb0..2c7c518 100644 --- a/tutorial.md +++ b/tutorial.md @@ -12798,7 +12798,7 @@ Recently Haskell has seen quite a bit of development of cryptography libraries as it serves as a excellent language for working with and manipulating algebraic structures found in cryptographic primitives. In addition to most of the basic hashing, elliptic curve and cipher suites libraries, Haskell has a excellent -standard cryptography library called *cryptonite* which provides the standard +standard cryptography library called `cryptonite` which provides the standard kitchen sink of most modern primitives. These include hash functions, elliptic curve cryptography, digital signature algorithms, ciphers, one time passwords, entropy generation and safe memory handling. @@ -16296,13 +16296,17 @@ of the runtime logic is stored across the `includes`, `utils` and `rts` folders. ```bash ghc-8.8.2 +├── compiler +│   └── prelude +│ └── primops.txt.pp # Definitions of primops +├── compiler ├── includes -│   ├── rts # Public interface for RTS -│   └── stg # Definitions for STG langauge +│   ├── rts # Public interface for RTS +│   └── stg # Definitions for STG langauge ├── utils -│   ├── genapply # Generates Cmm closure application boilerplate -│   └── genprimopcode # Generates Primop builtin operations for GHC -│   └── deriveConstants # Machine specific information about register and sizes +│   ├── genapply # Generates Cmm closure application boilerplate +│   ├── genprimopcode # Generates Primop builtin operations for GHC +│   └── deriveConstants # Machine specific information about register and sizes └── rts    ├── hooks    ├── linker @@ -16370,9 +16374,9 @@ that define the Cmm macros in terms of the Haskell datatypes defined in the (pointer size, word sizes, etc) of the target platform For `genprimop`, the primops are generated from a custom domain specific -langauge specified in the `compiler/prelude/primops.txt.pp` which defines the -primops, their arity, commutative and associvaity properties and the machine -types they operate over. An example for integer addition for (`+#`) looks like: +langauge specified in `primops.txt.pp` which defines the primops, their arity, +commutative and associvaity properties and the machine types they operate over. +An example for integer addition for (`+#`) looks like: ```haskell primtype Int# From a980ed0d886d8a4fec85e34250a1cf9f78280364 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 20 Feb 2020 21:50:11 +0000 Subject: [PATCH 23/45] Misc fixes --- .gitignore | 1 + Makefile | 4 ++++ errata.md | 2 ++ tutorial.md | 10 +++++----- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 errata.md diff --git a/.gitignore b/.gitignore index d216115..83a272b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ tutorial.tex .stack-work dist-newstyle resources/*.eps +errata.* .brokdb diff --git a/Makefile b/Makefile index 49a0092..a3b6b20 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,10 @@ webpdf: $(INPUT) includes $(COVER) $(BACK) ./includes < $< \ | $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --include-in-header $(UNICODE_MAP) --pdf-engine=xelatex $(FLAGS) $(LFLAGS) $(PFLAGS) -o $(WPDF) +errata: + $(PANDOC) -i errata.md -o errata.tex + $(PANDOC) -i errata.md -o errata.html + links: brok tutorial.md diff --git a/errata.md b/errata.md new file mode 100644 index 0000000..2d8368a --- /dev/null +++ b/errata.md @@ -0,0 +1,2 @@ +Errata +====== diff --git a/tutorial.md b/tutorial.md index 2c7c518..b630c51 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1352,14 +1352,14 @@ interface which is linked against other Haskell modules. A module may reexport symbols from other modules. ```haskell -# A module starts with its export declarations of symbols declared in this file. +-- A module starts with its export declarations of symbols declared in this file. module MyModule (myExport1, myExport2) where -# Followed by a set of imports of symbols from other files +-- Followed by a set of imports of symbols from other files import OtherModule (myImport1, myImport2) -# Rest of the logic and definitions in the module follow -# ... +-- Rest of the logic and definitions in the module follow +-- ... ``` Modules dependency graphs optionally may by cyclic (i.e. they import symbols @@ -2021,7 +2021,7 @@ An operator is a function that can be applied using infix syntax or partially applied using a section. Operators can be defined to use any combination the special ASCII symbols or any unicode symbol. -`!` `#` `%` `&` `*` `+` `.` `/` `<` `=` >` `?` `@` `\` `^` `|` `-` `~` `:` +`!` `#` `%` `&` `*` `+` `.` `/` `<` `=` `>` `?` `@` `\` `^` `|` `-` `~` `:` The following are reserved syntax and cannot be overloaded: From cefcd8180e127990820d26b3177a07b335c78c81 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Sat, 22 Feb 2020 08:58:30 +0000 Subject: [PATCH 24/45] Write more --- tutorial.md | 93 +++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/tutorial.md b/tutorial.md index b630c51..e64f586 100644 --- a/tutorial.md +++ b/tutorial.md @@ -273,29 +273,9 @@ extra-package-dbs: [] Cabal ----- -[Cabal](https://www.haskell.org/cabal/) is the build system for Haskell. Cabal -is also the standard build tool for Haskell source supported by GHC. Cabal can -be used simultaneously with Stack or standalone with cabal new-build. - -For example, to install the [parsec](http://hackage.haskell.org/package/parsec) -package to your system from [Hackage](#hackage), the upstream source of Haskell -packages, invoke the ``install`` command: - -```bash -$ cabal install parsec # latest version -$ cabal install parsec==3.1.5 # exact version -``` - -The usual build invocation for Haskell packages is the following: - -```bash -$ cabal get parsec # fetch source -$ cd parsec-3.1.5 - -$ cabal configure -$ cabal build -$ cabal install -``` +Cabal is the build system for Haskell. Cabal is also the standard build tool +for Haskell source supported by GHC. Cabal can be used simultaneously with Stack + or standalone with cabal new-build. To update the package index from Hackage, run: @@ -477,9 +457,25 @@ directory. documentation: True ``` -See: +Cabal can also be used to install packages globally to the system PATH. For +example the [parsec](#parsec) package to your system from [Hackage](#hackage), +the upstream source of Haskell packages, invoke the ``install`` command: -* [Cabal User Guide](https://www.haskell.org/cabal/users-guide/) +```bash +$ cabal install parsec --installdir=~/.local/bin # latest version +``` + +To download the source for a package, we can use the `get` command to retrieve +the source from Hackage. + +```bash +$ cabal get parsec # fetch source +$ cd parsec-3.1.5 + +$ cabal configure +$ cabal build +$ cabal install +``` Cabal New-Build --------------- @@ -1506,14 +1502,15 @@ The following *ground types* are quite common: * `Float` - Machine floating point values * `Double` - Machine double floating point values -Parameterised types which also frequently appear and are are associated with -common data structures such as lists and tuples. +*Parameterised types* consist of a type and several *type parameters* indicated +as lower case *type variables*. These are associated with common data structures +such as [lists](#lists) and [tuples](#tuples). * `[a]` -- Homogeneous lists with elements of a type `a` * `(a,b)` -- Tuple with two elements of type `a` and `b` * `(a,b,c)` -- Tuple with three elements of type `a`, `b`, and `c` -The type system grows **quite** a bit from here, but these are the foundational +The type system grows quite a bit from here, but these are the foundational types you'll first encounter. See the later chapters for all types off advanced features that can be optionally turned on. @@ -1533,12 +1530,12 @@ the right-hand side: ```haskell myFunction x y = x ^ 2 + y ^ 2 - ^ ^ ^ ^^^^^^^^^^^^^ - | | | | - | | | +-- function body - | | +------ second argument - | +-------- first argument - +-------------- function +-- ^ ^ ^ ^^^^^^^^^^^^^ +-- | | | | +-- | | | +-- function body +-- | | +------ second argument +-- | +-------- first argument +-- +-------------- function ``` The *type-level* definition is the function name followed by the type of its @@ -1547,12 +1544,12 @@ function body, meaning the type of value yielded by the function itself. ```haskell myFunction :: Int -> Int -> Int - ^ ^ ^ ^^^^^ - | | | | - | | | +- return type - | | +------ second argument - | +------------ first argument - +----------------------- function +-- ^ ^ ^ ^^^^^ +-- | | | | +-- | | | +- return type +-- | | +------ second argument +-- | +------------ first argument +-- +----------------------- function ``` Here is a simple example of a function which adds two integers. @@ -1637,7 +1634,7 @@ Fortran) others have flexible arity (like Python) where a variable of number of arguments can be passed. Haskell follows a very simple rule: all functions in Haskell take a single argument. For multi-argument functions (some of which we've already seen), arguments will be individually applied until the function -is *saturated* and the function body is evaluated. This is known as “currying”. +is *saturated* and the function body is evaluated. For example, the add function from above can be partially applied to produce an add1 function: @@ -1676,7 +1673,7 @@ Algebraic Datatypes ------------------- Custom datatypes in Haskell are defined with the `data` keyword followed by the -the type name, it's parameters, and then a set of **constructors**. The possible +the type name, it's parameters, and then a set of *constructors*. The possible constructors are either *sum types* or of *product types*. All datatypes in Haskell can expressed as sums of products. A sum type is a set of options that is delimited by a pipe. A datatype is inhabited by only a single value sum type @@ -7254,11 +7251,6 @@ unpack :: ByteString -> String ~~~~ {.haskell include="src/07-text-bytestring/bytestring.hs"} ~~~~ -See: - -* [Bytestring: Bits and Pieces](https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/bytestring-bits-and-pieces) -* [ByteString](http://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html) - Printf ------ @@ -13846,9 +13838,10 @@ Databases Haskell has bindings for most major databases and persistence engines. Generally the libraries will consist of two different layers. The raw bindings which wrap the C library or wire protocol will usually be called `-simple`. So for example -`postgres-simple`. While higher level libraries will typically depend on this -library for the bindings and provide higher level interfaces for building -queries, managing transactions, and connection pooling. +`postgresql-simple` is the Haskell library for interfacing with the C library +`libpq-dev`. Higher level libraries will depend on this library for the bindings +and provide higher level interfaces for building queries, managing transactions, +and connection pooling. Postgres -------- From fda024dcc6f1863465036228b03f1a5910388a63 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Sat, 22 Feb 2020 09:23:21 +0000 Subject: [PATCH 25/45] Fix Conduit depreccations --- src/25-streaming/ci | 10 ++++++++++ src/25-streaming/conduit.hs | 19 +++++++++---------- src/25-streaming/example.cabal | 18 ++++++++++++++++++ src/25-streaming/stack.yaml | 3 +++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100755 src/25-streaming/ci create mode 100644 src/25-streaming/example.cabal create mode 100644 src/25-streaming/stack.yaml diff --git a/src/25-streaming/ci b/src/25-streaming/ci new file mode 100755 index 0000000..40de92f --- /dev/null +++ b/src/25-streaming/ci @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive conduit.hs +stack exec ghc -- -e ":q" --interactive lazyio.hs +stack exec ghc -- -e ":q" --interactive pipes.hs +stack exec ghc -- -e ":q" --interactive pipes_file.hs +stack exec ghc -- -e ":q" --interactive pipes_io.hs +#stack exec ghc -- -e ":q" --interactive pipes_safe.hs diff --git a/src/25-streaming/conduit.hs b/src/25-streaming/conduit.hs index 8bb8b42..207f4c6 100644 --- a/src/25-streaming/conduit.hs +++ b/src/25-streaming/conduit.hs @@ -1,26 +1,25 @@ {-# LANGUAGE MultiWayIf #-} -import Data.Conduit import Control.Monad.Trans +import Data.Conduit import qualified Data.Conduit.List as CL -source :: Source IO Int -source = CL.sourceList [1..100] +source :: ConduitT () Int IO () +source = CL.sourceList [1 .. 100] -conduit :: Conduit Int IO String +conduit :: ConduitT Int String IO () conduit = do val <- await - liftIO $ print val case val of Nothing -> return () Just n -> do - if | n `mod` 15 == 0 -> yield "FizzBuzz" - | n `mod` 5 == 0 -> yield "Fizz" - | n `mod` 3 == 0 -> yield "Buzz" - | otherwise -> return () + if | n `mod` 15 == 0 -> yield "FizzBuzz" + | n `mod` 5 == 0 -> yield "Fizz" + | n `mod` 3 == 0 -> yield "Buzz" + | otherwise -> return () conduit -sink :: Sink String IO () +sink :: ConduitT String o IO () sink = CL.mapM_ putStrLn main :: IO () diff --git a/src/25-streaming/example.cabal b/src/25-streaming/example.cabal new file mode 100644 index 0000000..b884e9b --- /dev/null +++ b/src/25-streaming/example.cabal @@ -0,0 +1,18 @@ +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple + +library + default-language: Haskell2010 + build-depends: + base >=4.6 && <4.14 + , conduit >=1.3.1.2 && <1.4 + , mtl >=2.2.2 && <2.3 + , pipes >=4.3.13 && <4.4 + , pipes-safe >2.3 && <2.4 + --, zeromq-haskell diff --git a/src/25-streaming/stack.yaml b/src/25-streaming/stack.yaml new file mode 100644 index 0000000..cf51927 --- /dev/null +++ b/src/25-streaming/stack.yaml @@ -0,0 +1,3 @@ +resolver: lts-14.20 +extra-deps: +- zeromq-haskell-0.8.4 From 3a57473f4079a9d215461656b856ce71caada911 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Sat, 22 Feb 2020 18:33:56 +0000 Subject: [PATCH 26/45] Chapter 26 CI --- src/26-data-formats/aeson_derive.hs | 32 ++++++++++-------- src/26-data-formats/ci | 11 +++++++ src/26-data-formats/example.cabal | 36 +++++++++------------ src/26-data-formats/stack.yaml | 36 +++------------------ src/26-data-formats/yaml.hs | 50 ++++++++++++++++------------- src/ci | 32 ++++++++++++++++++ 6 files changed, 108 insertions(+), 89 deletions(-) create mode 100755 src/26-data-formats/ci diff --git a/src/26-data-formats/aeson_derive.hs b/src/26-data-formats/aeson_derive.hs index 71589d6..611e95d 100644 --- a/src/26-data-formats/aeson_derive.hs +++ b/src/26-data-formats/aeson_derive.hs @@ -1,23 +1,27 @@ -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} -import Data.Text import Data.Aeson +import Data.ByteString.Lazy.Char8 as BL +import Data.Text import GHC.Generics -import qualified Data.ByteString.Lazy as BL -data Refs = Refs - { a :: Text - , b :: Text - } deriving (Show,Generic,FromJSON,ToJSON) +data Refs + = Refs + { a :: Text, + b :: Text + } + deriving (Show, Generic, FromJSON, ToJSON) -data Data = Data - { id :: Int - , name :: Text - , price :: Int - , tags :: [Text] - , refs :: Refs - } deriving (Show,Generic,FromJSON,ToJSON) +data Data + = Data + { id :: Int, + name :: Text, + price :: Int, + tags :: [Text], + refs :: Refs + } + deriving (Show, Generic, FromJSON, ToJSON) main :: IO () main = do diff --git a/src/26-data-formats/ci b/src/26-data-formats/ci new file mode 100755 index 0000000..f0ea914 --- /dev/null +++ b/src/26-data-formats/ci @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive aeson_custom.hs +stack exec ghc -- -e ":q" --interactive aeson_derive.hs +stack exec ghc -- -e ":q" --interactive aeson_structured.hs +stack exec ghc -- -e ":q" --interactive aeson_unstructured.hs +stack exec ghc -- -e ":q" --interactive cassava_structured.hs +stack exec ghc -- -e ":q" --interactive cassava_unstructured.hs +stack exec ghc -- -e ":q" --interactive yaml.hs diff --git a/src/26-data-formats/example.cabal b/src/26-data-formats/example.cabal index 572a106..a6d1cc0 100644 --- a/src/26-data-formats/example.cabal +++ b/src/26-data-formats/example.cabal @@ -1,21 +1,17 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2016 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 -tested-with: GHC == 7.6.3 +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - - build-depends: - aeson -any, - yaml -any, - text -any, - bytestring -any, - pretty-show -any, - base >= 4.6 && <4.10 - - default-language: Haskell2010 +library + default-language: Haskell2010 + build-depends: + aeson >=1.4.6.0 && <1.5 + , base >=4.6 && <4.14 + , cassava >=0.5.2.0 && <0.6 + , pretty-show >=1.10 && <1.11 + , yaml >=0.11.2.0 && <0.12 diff --git a/src/26-data-formats/stack.yaml b/src/26-data-formats/stack.yaml index d1bcc2f..16e4f9c 100644 --- a/src/26-data-formats/stack.yaml +++ b/src/26-data-formats/stack.yaml @@ -1,32 +1,4 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md - -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-4.2 - -# Local packages, usually specified by relative directory name -packages: -- '.' - -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) -extra-deps: [] - -# Override default flag values for local packages and extra-deps -flags: {} - -# Extra package databases containing global packages -extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] +resolver: lts-14.20 +extra-deps: +- pretty-show-1.10 +- haskell-lexer-1.1 diff --git a/src/26-data-formats/yaml.hs b/src/26-data-formats/yaml.hs index 3212c6c..6eb4116 100644 --- a/src/26-data-formats/yaml.hs +++ b/src/26-data-formats/yaml.hs @@ -1,37 +1,41 @@ -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-} -import Data.Yaml - -import Data.Text (Text) import qualified Data.ByteString as BL - +import Data.Text (Text) +import Data.Yaml import GHC.Generics -data Invoice = Invoice - { invoice :: Int - , date :: Text - , bill :: Billing - } deriving (Show,Generic,FromJSON) +data Invoice + = Invoice + { invoice :: Int, + date :: Text, + bill :: Billing + } + deriving (Show, Generic, FromJSON) -data Billing = Billing - { address :: Address - , family :: Text - , given :: Text - } deriving (Show,Generic,FromJSON) +data Billing + = Billing + { address :: Address, + family :: Text, + given :: Text + } + deriving (Show, Generic, FromJSON) -data Address = Address - { lines :: Text - , city :: Text - , state :: Text - , postal :: Int - } deriving (Show,Generic,FromJSON) +data Address + = Address + { lines :: Text, + city :: Text, + state :: Text, + postal :: Int + } + deriving (Show, Generic, FromJSON) main :: IO () main = do contents <- BL.readFile "example.yaml" - let (res :: Either String Invoice) = decodeEither contents + let (res :: Either ParseException Invoice) = decodeEither' contents case res of + Left err -> print err Right val -> print val - Left err -> putStrLn err diff --git a/src/ci b/src/ci index 60116db..ccc4348 100755 --- a/src/ci +++ b/src/ci @@ -50,6 +50,10 @@ echo -n "12-gadts .. " (cd 12-gadts && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "13-lambda-calculus .. " +(cd 13-lambda-calculus && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "14-interpreters .. " (cd 14-interpreters && bash ci) echo -e "\e[1;32mOK\e[0m" @@ -86,10 +90,30 @@ echo -n "22-concurrency .. " (cd 22-concurrency && bash ci) echo -e "\e[1;32mOK\e[0m" +#echo -n "23-graphics .. " +#(cd 23-graphics && bash ci) +#echo -e "\e[1;32mOK\e[0m" + echo -n "24-parsing .. " (cd 24-parsing && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "25-streaming .. " +(cd 25-streaming && bash ci) +echo -e "\e[1;32mOK\e[0m" + +echo -n "26-data-formats .. " +(cd 25-data-formats && bash ci) +echo -e "\e[1;32mOK\e[0m" + +echo -n "27-web .. " +(cd 27-web && bash ci) +echo -e "\e[1;32mOK\e[0m" + +echo -n "28-databases .. " +(cd 28-databases && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "29-ghc .. " (cd 29-ghc && bash ci) echo -e "\e[1;32mOK\e[0m" @@ -98,6 +122,14 @@ echo -n "30-languages .. " (cd 30-languages && bash ci) echo -e "\e[1;32mOK\e[0m" +echo -n "31-template-haskell .. " +(cd 31-template-haskell && bash ci) +echo -e "\e[1;32mOK\e[0m" + +echo -n "32-cryptography .. " +(cd 32-cryptography && bash ci) +echo -e "\e[1;32mOK\e[0m" + echo -n "33-categories .. " (cd 33-categories && bash ci) echo -e "\e[1;32mOK\e[0m" From ce4fafb14032e85c1e7a8b439441de32235c27cb Mon Sep 17 00:00:00 2001 From: sdiehl Date: Sat, 22 Feb 2020 18:53:30 +0000 Subject: [PATCH 27/45] Chapter 27 CI --- src/27-web/ci | 13 ++++++++++++ src/27-web/example.cabal | 45 ++++++++++++++++++++++------------------ src/27-web/http.hs | 20 +++++++++--------- src/27-web/warp.hs | 4 ++-- 4 files changed, 50 insertions(+), 32 deletions(-) create mode 100755 src/27-web/ci diff --git a/src/27-web/ci b/src/27-web/ci new file mode 100755 index 0000000..b350911 --- /dev/null +++ b/src/27-web/ci @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive blaze.hs +stack exec ghc -- -e ":q" --interactive blaze_instance.hs +#stack exec ghc -- -e ":q" --interactive hastache.hs +#stack exec ghc -- -e ":q" --interactive hastache_generic.hs +stack exec ghc -- -e ":q" --interactive http.hs +stack exec ghc -- -e ":q" --interactive lucid.hs +stack exec ghc -- -e ":q" --interactive req.hs +stack exec ghc -- -e ":q" --interactive scotty.hs +stack exec ghc -- -e ":q" --interactive warp.hs diff --git a/src/27-web/example.cabal b/src/27-web/example.cabal index ba6e4c2..860dc0e 100644 --- a/src/27-web/example.cabal +++ b/src/27-web/example.cabal @@ -1,22 +1,27 @@ -name: example -version: 0.1.0.0 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2020 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 +cabal-version: >=1.10 +name: example +version: 0.1.0.0 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library +library default-language: Haskell2010 - build-depends: - base >= 4.6 && <4.14, - mtl >= 2.2 && <2.3, - text >= 1.2 && <1.3, - aeson >= 1.4 && <1.5, - req >= 3.0 && <3.1, - lucid >= 2.9.12 && <2.10, - scotty >= 0.11 && <0.12, - Spock >= 0.13 && <0.14, - servant >= 0.16 && <0.17, - servant-server >= 0.16 && <0.17 + build-depends: + aeson >=1.4 && <1.5 + , async >=2.2.2 && <2.3 + , base >=4.6 && <4.14 + , http-client >=0.6 && <0.7 + , http-types >=0.12.3 && <0.13 + , lucid >=2.9.12 && <2.10 + , mtl >=2.2 && <2.3 + , req >=3.0 && <3.1 + , scotty >=0.11 && <0.12 + , servant >=0.16 && <0.17 + , servant-server >=0.16 && <0.17 + , Spock >=0.13 && <0.14 + , text >=1.2 && <1.3 + , wai >=3.2.2.1 && <3.3 + , warp >=3.3.0 && <3.4 diff --git a/src/27-web/http.hs b/src/27-web/http.hs index e0a4108..3aa4d88 100644 --- a/src/27-web/http.hs +++ b/src/27-web/http.hs @@ -1,28 +1,28 @@ {-# LANGUAGE OverloadedStrings #-} -import Network.HTTP.Types -import Network.HTTP.Client import Control.Applicative import Control.Concurrent.Async +import Network.HTTP.Client +import Network.HTTP.Types type URL = String get :: Manager -> URL -> IO Int get m url = do - req <- parseUrl url - statusCode <$> responseStatus <$> httpNoBody req m + req <- parseUrlThrow url + statusCode . responseStatus <$> httpNoBody req m single :: IO Int single = do - withManager defaultManagerSettings $ \m -> do - get m "http://haskell.org" + manager <- newManager defaultManagerSettings + get manager "http://haskell.org" parallel :: IO [Int] parallel = do - withManager defaultManagerSettings $ \m -> do - -- Fetch w3.org 10 times concurrently - let urls = replicate 10 "http://www.w3.org" - mapConcurrently (get m) urls + manager <- newManager defaultManagerSettings + -- Fetch w3.org 10 times concurrently + let urls = replicate 10 "http://www.w3.org" + mapConcurrently (get manager) urls main :: IO () main = do diff --git a/src/27-web/warp.hs b/src/27-web/warp.hs index dd517fe..5de72d7 100644 --- a/src/27-web/warp.hs +++ b/src/27-web/warp.hs @@ -1,11 +1,11 @@ {-# LANGUAGE OverloadedStrings #-} +import Network.HTTP.Types import Network.Wai import Network.Wai.Handler.Warp (run) -import Network.HTTP.Types app :: Application -app req = return $ responseLBS status200 [] "Engage!" +app req respond = respond $ responseLBS status200 [] "Make it so." main :: IO () main = run 8000 app From e5e5d6c9b643da6e5166afbffe1338be8b9fa7b8 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Sat, 22 Feb 2020 19:21:37 +0000 Subject: [PATCH 28/45] Chapter 29 CI --- src/28-databases/ci | 12 ++++++++++ src/28-databases/example.cabal | 42 ++++++++++++++-------------------- src/28-databases/stack.yaml | 1 + src/29-ghc/ci | 9 ++++---- src/29-ghc/closure_size.hs | 33 ++++++++++++++------------ src/29-ghc/example.cabal | 41 ++++++++++++++++----------------- src/29-ghc/prim.hs | 6 +++-- src/29-ghc/stack.yaml | 4 +++- tutorial.md | 4 ++-- 9 files changed, 83 insertions(+), 69 deletions(-) create mode 100755 src/28-databases/ci diff --git a/src/28-databases/ci b/src/28-databases/ci new file mode 100755 index 0000000..8093579 --- /dev/null +++ b/src/28-databases/ci @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive acid.hs +stack exec ghc -- -e ":q" --interactive hedis.hs +stack exec ghc -- -e ":q" --interactive hedis_pubsub.hs +stack exec ghc -- -e ":q" --interactive postgres.hs +stack exec ghc -- -e ":q" --interactive postgres_custom.hs +stack exec ghc -- -e ":q" --interactive postgres_qq.hs +stack exec ghc -- -e ":q" --interactive selda.hs +stack exec ghc -- -e ":q" --interactive sqlite.hs diff --git a/src/28-databases/example.cabal b/src/28-databases/example.cabal index ae3f512..c62cfe4 100644 --- a/src/28-databases/example.cabal +++ b/src/28-databases/example.cabal @@ -1,26 +1,18 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2020 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 +cabal-version: >=1.10 +name: example +version: 0.1.0.0 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - default-language: Haskell2010 - build-depends: - base >= 4.6 && <4.14, - mtl >= 2.2 && <2.3, - async >= 2.0 && <2.3, - text >= 1.2 && <1.3, - bytestring >= 0.9 && <0.11, - - safecopy >= 0.8 && <0.10, - containers >= 0.5 && <0.7, - resource-pool >= 0.2 && <0.3, - - hedis >= 0.6 && <0.13, - acid-state >= 0.14 && <0.15, - postgresql-simple >= 0.5 && <0.7, - sqlite-simple >= 0.4 && <0.5 +library + default-language: Haskell2010 + build-depends: + acid-state + , base >=4.6 && <4.14 + , hedis >=0.12 && <0.13 + , postgresql-simple >=0.6 && <0.7 + , selda >=0.5.1.0 && <0.6 + , sqlite-simple >=0.4 && <0.5 diff --git a/src/28-databases/stack.yaml b/src/28-databases/stack.yaml index 169d9c1..ab9f7d5 100644 --- a/src/28-databases/stack.yaml +++ b/src/28-databases/stack.yaml @@ -3,5 +3,6 @@ packages: - '.' extra-deps: - acid-state-0.14.3 +- selda-0.5.1.0 flags: {} extra-package-dbs: [] diff --git a/src/29-ghc/ci b/src/29-ghc/ci index 101429c..1a9df61 100755 --- a/src/29-ghc/ci +++ b/src/29-ghc/ci @@ -1,14 +1,15 @@ #!/usr/bin/env bash set -e -stack exec ghc -- -e ":q" --interactive closure_size.hs -stack exec ghc -- -e ":q" --interactive cmm_include.hs +stack build +#stack exec ghc -- -e ":q" --interactive closure_size.hs +#stack exec ghc -- -e ":q" --interactive cmm_include.hs stack exec ghc -- -e ":q" --interactive dictionaries.hs stack exec ghc -- -e ":q" --interactive ekg.hs stack exec ghc -- -e ":q" --interactive example.hs stack exec ghc -- -e ":q" --interactive heapview.hs -stack exec ghc -- -e ":q" --interactive hie.hs -stack exec ghc -- -e ":q" --interactive io_impl.hs +#stack exec ghc -- -e ":q" --interactive hie.hs +#stack exec ghc -- -e ":q" --interactive io_impl.hs stack exec ghc -- -e ":q" --interactive monad_prim.hs stack exec ghc -- -e ":q" --interactive prim.hs stack exec ghc -- -e ":q" --interactive profile.hs diff --git a/src/29-ghc/closure_size.hs b/src/29-ghc/closure_size.hs index 48ed93a..b11b35b 100644 --- a/src/29-ghc/closure_size.hs +++ b/src/29-ghc/closure_size.hs @@ -1,30 +1,35 @@ -{-# LANGUAGE MagicHash, UnboxedTuples #-} -{-# OPTIONS_GHC -O1 #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} + +--{-# OPTIONS_GHC -O1 #-} module Main where -import GHC.Exts -import GHC.Base import Foreign +import GHC.Base +import GHC.Exts -data Size = Size - { ptrs :: Int - , nptrs :: Int - , size :: Int - } deriving (Show) +data Size + = Size + { ptrs :: Int, + nptrs :: Int, + size :: Int + } + deriving (Show) unsafeSizeof :: a -> Size unsafeSizeof a = case unpackClosure# a of (# x, ptrs, nptrs #) -> - let header = sizeOf (undefined :: Int) - ptr_c = I# (sizeofArray# ptrs) - nptr_c = I# (sizeofByteArray# nptrs) `div` sizeOf (undefined :: Word) + let header = sizeOf (undefined :: Int) + ptr_c = I# (sizeofArray# ptrs) + nptr_c = I# (sizeofByteArray# nptrs) `div` sizeOf (undefined :: Word) payload = I# (sizeofArray# ptrs +# sizeofByteArray# nptrs) - size = header + payload - in Size ptr_c nptr_c size + size = header + payload + in Size ptr_c nptr_c size data A = A {-# UNPACK #-} !Int + data B = B Int main :: IO () diff --git a/src/29-ghc/example.cabal b/src/29-ghc/example.cabal index 4cb47d5..803d2e7 100644 --- a/src/29-ghc/example.cabal +++ b/src/29-ghc/example.cabal @@ -1,22 +1,21 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2016 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 -tested-with: GHC == 7.6.3 +cabal-version: >=1.10 +name: example +version: 0.1.0.0 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - - build-depends: - base >= 4.10 && <4.14, - ghc >=8.2.2 && <8.9, - ghc-paths -any, - ghc-boot-th -any, - hie-bios -any, - transformers -any, - mtl -any - - default-language: Haskell2010 +library + default-language: Haskell2010 + build-depends: + base >= 4.10 && <4.14 + , ghc == 8.6.5 + , ekg >= 0.4.0 && < 0.5 + , transformers >= 0.5.6 && < 0.6 + , ghc-boot-th >= 8.6.5 && < 8.7 + , mtl >= 2.2.2 && < 2.3 + , ghc-heap-view >= 0.6.1 && < 0.7 + , ghc-paths >= 0.1.0 && < 0.2 + , hie-bios >= 0.4.0 && < 0.5 diff --git a/src/29-ghc/prim.hs b/src/29-ghc/prim.hs index 052459c..1cca9fa 100644 --- a/src/29-ghc/prim.hs +++ b/src/29-ghc/prim.hs @@ -1,10 +1,12 @@ -{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} import GHC.Exts import GHC.Prim ex1 :: Bool -ex1 = gtChar# a# b# +ex1 = isTrue# (gtChar# a# b#) where !(C# a#) = 'a' !(C# b#) = 'b' diff --git a/src/29-ghc/stack.yaml b/src/29-ghc/stack.yaml index c06a8bd..d0af0b2 100644 --- a/src/29-ghc/stack.yaml +++ b/src/29-ghc/stack.yaml @@ -1,3 +1,5 @@ resolver: lts-14.7 extra-deps: - - hie-bios-0.3.2 + - ghc-8.6.5 + - ghc-heap-view-0.6.1 + - hie-bios-0.4.0 diff --git a/tutorial.md b/tutorial.md index e64f586..5b5ee97 100644 --- a/tutorial.md +++ b/tutorial.md @@ -13468,8 +13468,8 @@ which "snaplets" can extend the base server. Much of the Haskell.org infrastructure of packages and developmenet runs on top of Snap web applications. -HTTP ----- +HTTP Requests +------------- Haskell has a variety of HTTP request and processing libraries. The simplest and most flexible is the [HTTP library](https://hackage.haskell.org/package/HTTP). From 21d9bde18a842f3aab0055110ee882ee4ae74828 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Mon, 24 Feb 2020 12:30:47 +0000 Subject: [PATCH 29/45] Write more --- tutorial.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tutorial.md b/tutorial.md index 5b5ee97..78757be 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1863,7 +1863,6 @@ An equivalent loop in an imperative language would look like the following. ```python def powersOfTwo(n): - power = n square_list = [1] for i in range(1,n+1): square_list.append(2 ** i) @@ -3313,6 +3312,24 @@ Predicate will often prefix their function names with ``is``, as in ``isPositive isPositive = (>0) ``` +Functions which result in an Applicative or Monad type will often suffix their +name with a A for Applicative or M for Monad. For example: + +```haskell +liftM :: Monad m => (a -> r) -> m a -> m r +liftA :: Applicative f => (a -> b) -> f a -> f b +``` + +Functions which have *chirality* in which they traverse a data structure (i.e. +left-to-right or right-to-left) will often suffix the name with L or R for their +iteration pattern. This is useful because often times these type signatures +identical. + +```haskell +mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) +mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) +``` + Working with mutable structures or monadic state will often adopt the following naming conventions: @@ -6842,7 +6859,7 @@ not caught in the type system? data Bool = True | False isNotJust :: Maybe a -> Bool -isNotJust (Just x) = True +isNotJust (Just x) = True -- ??? isNotJust Nothing = False isJust :: Maybe a -> Bool From f2cc400c92a23d16c3bdc7a285e6879b79048e0d Mon Sep 17 00:00:00 2001 From: sdiehl Date: Mon, 24 Feb 2020 14:22:18 +0000 Subject: [PATCH 30/45] Remove eff, unstable --- resources/copyright.html | 6 +++++- resources/copyright.md | 5 +++++ tutorial.md | 25 +++++-------------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/resources/copyright.html b/resources/copyright.html index 0934bb0..0d1f70c 100644 --- a/resources/copyright.html +++ b/resources/copyright.html @@ -8,6 +8,10 @@
  • Kindle Version
  • Pull requests are always accepted for changes and additional content. This is a living document. The only way this document will stay up to date is through the kindness of readers like you and community patches and pull requests on Github.

    +

    If you’d like a physical copy of the text you can either print it for yourself (see Printable PDF) or purchase one online:

    +

    Author

    This text is authored by Stephen Diehl.

      @@ -18,6 +22,6 @@

      Special thanks for Erik Aker for copyediting assitance.

      License

      Copyright © 2009-2020 Stephen Diehl

      -

      This code included in the text is dedicated to the public domain. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

      +

      This code included in the text is dedicated to the public domain. You can copy, modify, distribute and perform the code, even for commercial purposes, all without asking permission.

      You may distribute this text in its full form freely, but may not reauthor or sublicense this work. Any reproductions of major portions of the text must include attribution.

      The software is provided “as is”, without warranty of any kind, express or implied, including But not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, Arising from, out of or in connection with the software or the use or other dealings in the software.

      diff --git a/resources/copyright.md b/resources/copyright.md index 387d2cf..602b677 100644 --- a/resources/copyright.md +++ b/resources/copyright.md @@ -14,6 +14,11 @@ living document. The only way this document will stay up to date is through the kindness of readers like you and community patches and [pull requests](https://github.com/sdiehl/wiwinwlh) on Github. +If you'd like a physical copy of the text you can either print it for yourself +(see Printable PDF) or purchase one online: + +* [**Blurb Publisher**](https://www.blurb.co.uk/b/9958091-what-i-wish-i-knew-when-learning-haskell) + Author ------ diff --git a/tutorial.md b/tutorial.md index 78757be..ce488a7 100644 --- a/tutorial.md +++ b/tutorial.md @@ -4849,11 +4849,10 @@ and can get by. However in recent years there have many other libraries that have explored the design space of alternative effect modeling systems. These systems are still quite early compared to the `mtl` but some are able to avoid some of the shortcomings of `mtl` in favour of newer algebraic models of -effects. The three most commonly used libraries are: +effects. The two most commonly used libraries are: * `fused-effects` * `polysemy` -* `eff` Polysemy -------- @@ -6296,9 +6295,9 @@ model. Model Strictness Description ------------- ------------- --------------- -Call-by-value Strict arguments evaluated before function entered -Call-by-name Non-strict arguments passed unevaluated -Call-by-need Non-strict arguments passed unevaluated but an expression is only evaluated once +Call-by-value Strict Arguments evaluated before function entered +Call-by-name Non-strict Arguments passed unevaluated +Call-by-need Non-strict Arguments passed unevaluated but an expression is only evaluated once Seq and WHNF ------------ @@ -7634,8 +7633,6 @@ resulting collected arguments must either converted into a single type or unpack ~~~~ {.haskell include="src/08-applicatives/variadic.hs"} ~~~~ -See: [Polyvariadic functions](http://okmij.org/ftp/Haskell/polyvariadic.html) -
      Error Handling @@ -7860,10 +7857,6 @@ The ``spoon`` function evaluates its argument to head normal form, while ~~~~ {.haskell include="src/09-errors/spoon.hs"} ~~~~ -See: - -* [Spoon](https://hackage.haskell.org/package/spoon) -
      @@ -8140,11 +8133,6 @@ following: ~~~~ {.haskell include="src/10-advanced-monads/free_impl.hs"} ~~~~ -See: - -* [Monads for Free!](http://www.andres-loeh.de/Free.pdf) -* [I/O is not a Monad](http://r6.ca/blog/20110520T220201Z.html) - Indexed Monads -------------- @@ -8834,7 +8822,6 @@ See: * [PHOAS](http://adam.chlipala.net/papers/PhoasICFP08/PhoasICFP08Talk.pdf) * [Encoding Higher-Order Abstract Syntax with Parametric Polymorphism](http://www.seas.upenn.edu/~sweirich/papers/itabox/icfp-published-version.pdf) - Final Interpreters ------------------ @@ -9552,11 +9539,9 @@ coerce :: Coercible * a b => a -> b class (~R#) k k a b => Coercible k a b ``` -[Safe Zero-cost Coercions for Haskell](http://cs.brynmawr.edu/~rae/papers/2014/coercible/coercible.pdf) -[Data.Coerce](https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Coerce.html#t:Coercible) - See: +* [Data.Coerce](https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Coerce.html#t:Coercible) * [Roles](https://ghc.haskell.org/trac/ghc/wiki/Roles) * [Roles: A New Feature of GHC](http://typesandkinds.wordpress.com/2013/08/15/roles-a-new-feature-of-ghc/) From d74216399bb13c290544dfe726f81332995c0068 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Tue, 25 Feb 2020 04:03:12 +0000 Subject: [PATCH 31/45] Write more --- src/29-ghc/factorial.cmm | 4 ++-- tutorial.md | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/29-ghc/factorial.cmm b/src/29-ghc/factorial.cmm index 40e2250..8927928 100644 --- a/src/29-ghc/factorial.cmm +++ b/src/29-ghc/factorial.cmm @@ -10,11 +10,11 @@ factorial { for: if (n <= 0 ) { - RET_N(acc); + return(acc); } else { acc = acc * n ; n = n - 1 ; goto for ; } - RET_N(0); + return(0); } diff --git a/tutorial.md b/tutorial.md index ce488a7..0c619e8 100644 --- a/tutorial.md +++ b/tutorial.md @@ -4098,6 +4098,7 @@ many things, including, but not limited to: - Read from or write to a file on the system - Establish an ``ssh`` connection to a remote computer - Take input from a radio antenna for signal processing + - Launch the missiles. Conceptualizing I/O as a monad enables the developer to access information outside the program, but also to use pure functions to operate on that @@ -5504,6 +5505,11 @@ algebraic data types. TupleSections -------------- +The TupleSections syntax extension allows tuples to be constructed similar to +how operator sections. With this extension enabled, tuples of arbitrary size can +be "partially" specified with commas and values given for specific positions in +the tuple. For example for a 2-tuple: + ```haskell {-# LANGUAGE TupleSections #-} @@ -5514,6 +5520,8 @@ second :: a -> (Bool, a) second = (True,) ``` +An example for a 7-tuple where three values are specified in the section. + ```haskell f :: t -> t1 -> t2 -> t3 -> (t, (), t1, (), (), t2, t3) f = (,(),,(),(),,) From 85968d2818c9cdd1edc6eb14d3f2cbecfbd49aed Mon Sep 17 00:00:00 2001 From: sdiehl Date: Tue, 25 Feb 2020 04:49:31 +0000 Subject: [PATCH 32/45] Write more --- src/32-cryptography/ECC.hs | 4 +-- tutorial.md | 54 ++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/32-cryptography/ECC.hs b/src/32-cryptography/ECC.hs index 3594025..c06182e 100644 --- a/src/32-cryptography/ECC.hs +++ b/src/32-cryptography/ECC.hs @@ -11,8 +11,6 @@ p1 = Ed25519.gen p2 :: Ed25519.PA p2 = Ed25519.mul p1 (3 :: Ed25519.Fr) --- ** -- - -- point addition p3 :: Ed25519.PA p3 = Ed25519.add p1 p2 @@ -37,7 +35,7 @@ p7 = Ed25519.frob p1 p8 :: Ed25519.PA p8 = Ed25519.gA --- convert affine to projective +-- convert affine coordinates to projective coordinates p9 :: Ed25519.PP p9 = Ed25519.fromA p8 diff --git a/tutorial.md b/tutorial.md index 0c619e8..2671b62 100644 --- a/tutorial.md +++ b/tutorial.md @@ -734,8 +734,8 @@ extra-deps: The ``stack`` command can be used to install packages and executables into either the current build environment or the global environment. For example, the -following command installs the executable for ``hlint``, [a popular linting tool for -Haskell](https://github.com/ndmitchell/hlint), and places it in the PATH: +following command installs the executable for ``hlint``, [a popular linting tool +for Haskell](#hlint), and places it in the PATH: ```bash $ stack install hlint @@ -1966,7 +1966,7 @@ fib n = fib (n-1) + fib (n-2) ```haskell fib :: Integer -> Integer -fib n = case n of +fib m = case m of 0 -> 0 1 -> 1 n -> fib (n-1) + fib(n-2) @@ -6530,8 +6530,6 @@ f !x !y = x + y On a module-level this effectively makes Haskell a call-by-value language with some caveats. All arguments to functions are now explicitly evaluated and all data in constructors within this module are in head normal form by construction. -However there are some subtle points to this that are better explained in the -language guide. Deepseq ------- @@ -12346,7 +12344,7 @@ spawn :: NFData a => Par a -> Par (IVar a) ~~~~ {.haskell include="src/22-concurrency/par.hs"} ~~~~ -async +Async ----- Async is a higher level set of functions that work on top of Control.Concurrent @@ -16104,13 +16102,43 @@ Cmm Description ``I32`` 32-bit integer ``I64`` 64-bit integer +Inside of Cmm logic there are several functions which are commonly invoked: + +* `Sp_adj` - Adjusts the stack pointer. +* `GET_ENTRY` - +* `ENTER` - +* `jump` - + +```cpp +stg_init_finish +{ + jump StgReturn; +} + +stg_init +{ + W_ next; + Sp = W_[BaseReg + OFFSET_StgRegTable_rSp]; + next = W_[Sp]; + Sp_adj(1); + jump next; +} +``` + +```cpp +#define SIZEOF_W 8 /* or 4 depending on platform */ +#define WDS(n) ((n)*SIZEOF_W) +#define Sp(n) W_[Sp + WDS(n)] +#define Hp(n) W_[Hp + WDS(n)] +#define Sp_adj(n) Sp = Sp + WDS(n) +#define Hp_adj(n) Hp = Hp + WDS(n) +``` Many of the predefined closures (``stg_ap_p_fast``, etc) are themselves mechanically generated and more or less share the same form ( a giant switch statement on closure type, update frame, stack adjustment). Inside of GHC is a -file named ``GenApply.hs`` that generates most of these functions. See the Gist -link in the reading section for the current source file that GHC generates. For -example the output for ``stg_ap_p_fast``. +file named ``GenApply.hs`` that generates most of these functions. For example +the output for ``stg_ap_p_fast``. ```cpp stg_ap_p_fast @@ -16172,14 +16200,6 @@ through GHC into an object and then using a special FFI invocation. ~~~~ {.haskell include="src/29-ghc/cmm_include.hs"} ~~~~ -Cmm Runtime: - -* [Apply.cmm](https://github.com/ghc/ghc/blob/master/rts/Apply.cmm) -* [StgStdThunks.cmm](https://github.com/ghc/ghc/blob/master/rts/StgStdThunks.cmm) -* [StgMiscClosures.cmm](https://github.com/ghc/ghc/blob/master/rts/StgMiscClosures.cmm) -* [PrimOps.cmm](https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm) -* [Updates.cmm](https://github.com/ghc/ghc/blob/master/rts/Updates.cmm) - Optimisation ------------ From 8b4846286a5da6fef02ef916aaab59c7d9be2fe9 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Tue, 25 Feb 2020 09:59:06 +0000 Subject: [PATCH 33/45] Write more --- src/19-numbers/scientific.hs | 11 +++++---- tutorial.md | 47 +++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/19-numbers/scientific.hs b/src/19-numbers/scientific.hs index 7d529d3..5267e3d 100644 --- a/src/19-numbers/scientific.hs +++ b/src/19-numbers/scientific.hs @@ -1,17 +1,18 @@ import Data.Scientific -c, h, g, a, k :: Scientific -c = scientific 299792458 (0) -- Speed of light +c , h, g, a, k :: Scientific +c = scientific 299792458 (0) -- Speed of light h = scientific 662606957 (-42) -- Planck's constant -g = scientific 667384 (-16) -- Gravitational constant +g = scientific 667384 (-16) -- Gravitational constant a = scientific 729735257 (-11) -- Fine structure constant -k = scientific 268545200 (-9) -- Khinchin Constant +k = scientific 268545200 (-9) -- Khinchin-Levy Constant tau :: Scientific -tau = fromFloatDigits (2*pi) +tau = fromFloatDigits (2 * pi) maxDouble64 :: Double maxDouble64 = read "1.7976931348623159e308" + -- Infinity maxScientific :: Scientific diff --git a/tutorial.md b/tutorial.md index 2671b62..121fd92 100644 --- a/tutorial.md +++ b/tutorial.md @@ -2939,12 +2939,12 @@ debugging segfaults with gdb. Breakpoints can be set `:break` and the call stack stepped through with `:forward` and `:back`. ```haskell -λ: :set -fbreak-on-exception -- Sets option for evaluation to stop on exception -λ: :break 2 15 -- Sets a break point at line 2, column 15 -λ: :trace main -- Run a function to generate a sequence of evaluation steps -λ: :hist -- Step backwards from a breakpoint through previous steps of evaluation -λ: :back -- Step backwards a single step at a time through the history -λ: :forward -- Step forward a single step at a time through the history +λ: :set -fbreak-on-exception -- Sets option for evaluation to stop on exception +λ: :break 2 15 -- Sets a break point at line 2, column 15 +λ: :trace main -- Run a function to generate a sequence of evaluation steps +λ: :hist -- Step back from a breakpoint through previous evaluation steps +λ: :back -- Step backwards a single step at a time through the history +λ: :forward -- Step forward a single step at a time through the history ``` Stack Traces @@ -6078,7 +6078,7 @@ associated with their methods. * `Foldable` * `Traversable` -![](img/class.png){ width=250px } +![](img/class.png){ width=500px } Instance Search --------------- @@ -9059,13 +9059,13 @@ The canonical example of a catamorphism is the factorial function which is a composition of a coalgebra creates a list from `n` to `1` and an algebra which multiplies the resulting list to a single result: -~~~~ {.haskell include="src/14-interpreters/catamorphism.hs"} +~~~~ {.haskell include="src/14-interpreters/factorial.hs"} ~~~~ Another example is unfolding of lambda calculus to perform a substitution over a variable. We can define a catamoprhism for traversing over the AST. -~~~~ {.haskell include="src/14-interpreters/factorial.hs"} +~~~~ {.haskell include="src/14-interpreters/catamorphism.hs"} ~~~~ Another use case would be to collect the free variables inside of the AST. This @@ -10995,7 +10995,7 @@ class (RealFrac a, Floating a) => RealFloat a ```
      -![](img/numerics.png){ width=250px } +![](img/numerics.png){ width=400px }
      Conversions between concrete numeric types ( from : left column, to : top row ) @@ -11010,18 +11010,23 @@ Word fromIntegral fromIntegral fromIntegral id fromIntegral f Integer fromIntegral fromIntegral fromIntegral fromIntegral id fromIntegral Rational fromRational fromRational truncate truncate truncate id -Arbitrary-precision Arirthmetic -------------------------------- +GMP Integers +------------ The ``Integer`` type in GHC is implemented by the GMP (``libgmp``) arbitrary -precision arithmetic library. Unlike the ``Int`` type the size of Integer -values is bounded only by the available memory. Most notably ``libgmp`` is one -of the few libraries that compiled Haskell binaries are dynamically linked -against. +precision arithmetic library. Unlike the ``Int`` type, the size of Integer +values is bounded only by the available memory. -An alternative library ``integer-simple`` can be linked in place of libgmp. +```haskell +λ: (2^64 :: Int) +0 +λ: (2^64 :: Integer) +18446744073709551616 +``` -See: [GHC, primops and exorcising GMP](http://www.well-typed.com/blog/32/) +Most notably ``libgmp`` is one of the few libraries that compiled Haskell +binaries are dynamically linked against. An alternative library +``integer-simple`` can be linked in place of libgmp. Complex Numbers --------------- @@ -12027,7 +12032,7 @@ be performed atomically and passed around symbolically. In the event that the runtime fails to commit a transaction, the `retry` function can rerun the logic contained in a `STM a`. -``` +```haskell atomically :: STM a -> IO a retry :: STM a ``` @@ -14281,11 +14286,9 @@ example = d <- desugarModule t -- DesugaredModule l <- loadModule d let c = coreModule d -- CoreModule - g <- getModuleGraph mapM showModule g - - return $ c + return c main :: IO () main = do From cdd2c38646cebdc23a60f39b2f8b3f08ccaae282 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Tue, 25 Feb 2020 10:13:58 +0000 Subject: [PATCH 34/45] Fix typos --- tutorial.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tutorial.md b/tutorial.md index 121fd92..cc433a2 100644 --- a/tutorial.md +++ b/tutorial.md @@ -13050,7 +13050,7 @@ $$ There are many types of pairings that can be computed. The `pairing` library implements the Ate pairing over several elliptic curve groups including the Barreto-Naehrig family and the BLS12-381 curve. These types of pairings are -used qquite frequently in modern cryptographic protocols such as the construction +used quite frequently in modern cryptographic protocols such as the construction of zkSNARKs. ~~~~ {.haskell include="src/32-cryptography/Pairing.hs"} @@ -13073,11 +13073,13 @@ Haskell has a variety of libraries for building zkSNARK protocols including libraries to build circuit representations of embedded domain specific languages and produce succinct pairing based zero knowledge proofs. -* [arithmetic-circuits](https://github.com/adjoint-io/arithmetic-circuits) - Construction arithmetic circuits and Rank-1 constraint systems (R1CS) in - Haskell. * [zkp](https://github.com/adjoint-io/zkp) - Implementation of the Groth16 - protocol in Haskell based on bilinear pairings. + protocol based on bilinear pairings. +* [bulletproofs](https://hackage.haskell.org/package/bulletproofs) - + Implementation of the Bulletproofs protocol. +* [arithmetic-circuits](https://github.com/adjoint-io/arithmetic-circuits) + Generic data structures for construction arithmetic circuits and Rank-1 + constraint systems (R1CS) in Haskell. Dates and Times =============== From de33fd8f0be896b1a5d6f03b2ed28dce347e9bf7 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 15:18:04 +0000 Subject: [PATCH 35/45] Fix TH examples --- src/12-gadts/ci | 2 +- src/13-lambda-calculus/church_encoding.hs | 8 ++-- src/13-lambda-calculus/ci | 8 ++++ src/13-lambda-calculus/debruijn.hs | 45 +++++++++++-------- src/30-languages/ci | 4 +- src/31-template-haskell/ci | 23 ++++++++++ src/31-template-haskell/cquote.hs | 19 ++++---- src/31-template-haskell/derive.hs | 3 +- src/31-template-haskell/enum_family_splice.hs | 12 +++-- src/31-template-haskell/example.cabal | 20 +++++++++ src/31-template-haskell/singleton_lib.hs | 37 +++++++++------ src/31-template-haskell/singleton_promote.hs | 36 ++++++++------- src/31-template-haskell/stack.yaml | 10 +++++ src/31-template-haskell/template_info.hs | 4 +- src/ci | 2 +- 15 files changed, 160 insertions(+), 73 deletions(-) create mode 100755 src/13-lambda-calculus/ci create mode 100755 src/31-template-haskell/ci create mode 100644 src/31-template-haskell/example.cabal create mode 100644 src/31-template-haskell/stack.yaml diff --git a/src/12-gadts/ci b/src/12-gadts/ci index a7a0ac5..2d592da 100755 --- a/src/12-gadts/ci +++ b/src/12-gadts/ci @@ -6,4 +6,4 @@ stack exec ghc -- -e ":q" --interactive gadt.hs stack exec ghc -- -e ":q" --interactive kindsignatures.hs #stack exec ghc -- -e ":q" --interactive phantom.hs stack exec ghc -- -e ":q" --interactive phantom_example.hs -stack exec ghc -- -e ":q" --interactive propositional_equal.hs +#stack exec ghc -- -e ":q" --interactive propositional_equal.hs diff --git a/src/13-lambda-calculus/church_encoding.hs b/src/13-lambda-calculus/church_encoding.hs index 07a6719..0c199a0 100644 --- a/src/13-lambda-calculus/church_encoding.hs +++ b/src/13-lambda-calculus/church_encoding.hs @@ -100,10 +100,10 @@ ex3 :: Integer ex3 = snd (pair 1 2) -- 2 -ex4 :: Integer -ex4 = head (tail (cons 1 (cons 2 nil))) +--ex4 :: Integer +--ex4 = head (tail (cons 1 (cons 2 nil))) -- 2 -ex5 :: Bool -ex5 = unbool (true `xor` false) +--ex5 :: Bool +--ex5 = unbool (true `xor` false) -- True diff --git a/src/13-lambda-calculus/ci b/src/13-lambda-calculus/ci new file mode 100755 index 0000000..9a2c1bc --- /dev/null +++ b/src/13-lambda-calculus/ci @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e +stack exec ghc -- -e ":q" --interactive church_encoding.hs +stack exec ghc -- -e ":q" --interactive church_list.hs +stack exec ghc -- -e ":q" --interactive debruijn.hs +stack exec ghc -- -e ":q" --interactive hoas.hs +stack exec ghc -- -e ":q" --interactive phoas.hs diff --git a/src/13-lambda-calculus/debruijn.hs b/src/13-lambda-calculus/debruijn.hs index 67ea021..1a57cc7 100644 --- a/src/13-lambda-calculus/debruijn.hs +++ b/src/13-lambda-calculus/debruijn.hs @@ -1,6 +1,7 @@ import Control.Monad -import Text.PrettyPrint import qualified Data.Map as Map +import Text.PrettyPrint +import Prelude hiding ((<>)) -- de Bruijn indices data DExp @@ -13,7 +14,7 @@ subst :: DExp -> Integer -> DExp -> DExp subst e n (Var n') | n == n' = e | otherwise = (Var n') -subst e n (Lam e') = Lam $ subst e (n+1) e' +subst e n (Lam e') = Lam $ subst e (n + 1) e' subst e n (App e1 e2) = App (subst e n e1) (subst e n e2) nf :: DExp -> DExp @@ -21,21 +22,20 @@ nf e@(Var _) = e nf (Lam e) = Lam (nf e) nf (App f a) = case whnf f of - Lam b -> nf (subst a 0 b) - f' -> App (nf f') (nf a) + Lam b -> nf (subst a 0 b) + f' -> App (nf f') (nf a) whnf :: DExp -> DExp whnf e@(Var _) = e whnf e@(Lam _) = e whnf (App f a) = case whnf f of - Lam b -> whnf (subst a 0 b) - f' -> App f' a - + Lam b -> whnf (subst a 0 b) + f' -> App f' a -- Pretty printer -parensIf :: Bool -> Doc -> Doc +parensIf :: Bool -> Doc -> Doc parensIf True = parens parensIf False = id @@ -43,12 +43,12 @@ class Pretty p where ppr :: Int -> p -> Doc instance Pretty DExp where - ppr _ (Var v) = integer (v+1) - ppr p (Lam f) = parensIf (p>0) $ text "λ " <> ppr p f - ppr p (App f x) = ppr' f <+> ppr' x - where - ppr' (Var v) = integer (v+1) - ppr' expr = parens $ ppr p expr + ppr _ (Var v) = integer (v + 1) + ppr p (Lam f) = parensIf (p > 0) $ text "λ " <> ppr p f + ppr p (App f x) = ppr' f <+> ppr' x + where + ppr' (Var v) = integer (v + 1) + ppr' expr = parens $ ppr p expr ppexpr :: DExp -> String ppexpr = render . ppr 0 @@ -63,32 +63,39 @@ data NExp type Ctx = Map.Map String Integer letters :: [String] -letters = [1..] >>= flip replicateM ['a'..'z'] +letters = [1 ..] >>= flip replicateM ['a' .. 'z'] shift :: Ctx -> NExp -> DExp shift c (EVar v) = Var (c Map.! v) shift c (EApp a b) = App (shift c a) (shift c b) shift c (ELam v body) = Lam (shift c' body) - where c' = Map.insert v 0 (Map.map (+1) c) + where + c' = Map.insert v 0 (Map.map (+ 1) c) toDeBruijn :: NExp -> DExp toDeBruijn = shift Map.empty fromDeBruijn :: DExp -> NExp fromDeBruijn = from 0 - where from n (Var i) = EVar (letters !! (n - (fromIntegral i) - 1)) - from n (Lam b) = ELam (letters !! n) (from (succ n) b) - from n (App f a) = EApp (from n f) (from n a) + where + from n (Var i) = EVar (letters !! (n - (fromIntegral i) - 1)) + from n (Lam b) = ELam (letters !! n) (from (succ n) b) + from n (App f a) = EApp (from n f) (from n a) i = ELam "a" (EVar "a") + k = ELam "a" (ELam "b" (EVar "a")) + s = ELam "a" (ELam "b" (ELam "c" (EApp (EApp (EVar "a") (EVar "c")) (EApp (EVar "b") (EVar "c"))))) ex1 = ppexpr $ toDeBruijn i + -- λ 1 ex2 = ppexpr $ toDeBruijn k + -- λ λ 2 ex3 = ppexpr $ toDeBruijn s + -- λ λ λ (3 1) (2 1) ex4 = fromDeBruijn $ toDeBruijn s -- ELam "a" (ELam "b" (ELam "c" (EApp (EApp (EVar "a") (EVar "c")) (EApp (EVar "b") (EVar "c"))))) diff --git a/src/30-languages/ci b/src/30-languages/ci index 8a8c2db..e0f0899 100755 --- a/src/30-languages/ci +++ b/src/30-languages/ci @@ -7,5 +7,5 @@ stack exec ghc -- -e ":q" --interactive llvm-irbuilder.hs stack exec ghc -- -e ":q" --interactive pretty.hs stack exec ghc -- -e ":q" --interactive prettysimple.hs stack exec ghc -- -e ":q" --interactive repline.hs -stack exec ghc -- -e ":q" --interactive unbound-generics.hs -stack exec ghc -- -e ":q" --interactive unbound.hs +#stack exec ghc -- -e ":q" --interactive unbound-generics.hs +#stack exec ghc -- -e ":q" --interactive unbound.hs diff --git a/src/31-template-haskell/ci b/src/31-template-haskell/ci new file mode 100755 index 0000000..c1b745f --- /dev/null +++ b/src/31-template-haskell/ci @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive Antiquote.hs +#stack exec ghc -- -e ":q" --interactive Class.hs +stack exec ghc -- -e ":q" --interactive cquote.hs +stack exec ghc -- -e ":q" --interactive derive.hs +stack exec ghc -- -e ":q" --interactive enum_family_splice.hs +stack exec ghc -- -e ":q" --interactive EnumFamily.hs +stack exec ghc -- -e ":q" --interactive Insert.hs +stack exec ghc -- -e ":q" --interactive Multiline.hs +stack exec ghc -- -e ":q" --interactive multiline_example.hs +stack exec ghc -- -e ":q" --interactive Quasiquote.hs +stack exec ghc -- -e ":q" --interactive quasiquote_use.hs +stack exec ghc -- -e ":q" --interactive Singleton.hs +stack exec ghc -- -e ":q" --interactive singleton_lib.hs +#stack exec ghc -- -e ":q" --interactive singleton_promote.hs +stack exec ghc -- -e ":q" --interactive Splice.hs +#stack exec ghc -- -e ":q" --interactive splice_class.hs +stack exec ghc -- -e ":q" --interactive splice_singleton.hs +stack exec ghc -- -e ":q" --interactive template_info.hs +stack exec ghc -- -e ":q" --interactive use_antiquote.hs diff --git a/src/31-template-haskell/cquote.hs b/src/31-template-haskell/cquote.hs index 13227c1..b92e8cf 100644 --- a/src/31-template-haskell/cquote.hs +++ b/src/31-template-haskell/cquote.hs @@ -1,12 +1,14 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} -import Text.PrettyPrint.Mainland -import qualified Language.C.Syntax as C import qualified Language.C.Quote.CUDA as Cuda +import qualified Language.C.Syntax as C +import Text.PrettyPrint.Mainland +import Text.PrettyPrint.Mainland.Class (Pretty (..)) cuda_fun :: String -> Int -> Float -> C.Func -cuda_fun fn n a = [Cuda.cfun| +cuda_fun fn n a = + [Cuda.cfun| __global__ void $id:fn (float *x, float *y) { int i = blockIdx.x*blockDim.x + threadIdx.x; @@ -16,7 +18,8 @@ __global__ void $id:fn (float *x, float *y) { |] cuda_driver :: String -> Int -> C.Func -cuda_driver fn n = [Cuda.cfun| +cuda_driver fn n = + [Cuda.cfun| void driver (float *x, float *y) { float *d_x, *d_y; @@ -37,12 +40,12 @@ void driver (float *x, float *y) { |] makeKernel :: String -> Float -> Int -> [C.Func] -makeKernel fn a n = [ - cuda_fun fn n a - , cuda_driver fn n +makeKernel fn a n = + [ cuda_fun fn n a, + cuda_driver fn n ] main :: IO () main = do let ker = makeKernel "saxpy" 2 65536 - mapM_ (print . ppr) ker + mapM_ (putDocLn . ppr) ker diff --git a/src/31-template-haskell/derive.hs b/src/31-template-haskell/derive.hs index e7818ef..713195b 100644 --- a/src/31-template-haskell/derive.hs +++ b/src/31-template-haskell/derive.hs @@ -1,9 +1,10 @@ {-# LANGUAGE TemplateHaskell #-} +import Data.Derive.Arbitrary import Data.DeriveTH import Test.QuickCheck -data Color = Red | Green | Blue deriving Show +data Color = Red | Green | Blue deriving (Show) $(derive makeArbitrary ''Color) diff --git a/src/31-template-haskell/enum_family_splice.hs b/src/31-template-haskell/enum_family_splice.hs index b531446..349aba5 100644 --- a/src/31-template-haskell/enum_family_splice.hs +++ b/src/31-template-haskell/enum_family_splice.hs @@ -1,22 +1,26 @@ {-# LANGUAGE DataKinds #-} -{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TemplateHaskell #-} - -import EnumFamily +{-# LANGUAGE TypeFamilies #-} import Data.Proxy -import GHC.TypeLits +import EnumFamily +import GHC.TypeLits hiding (Mod) type family Mod (m :: Nat) (n :: Nat) :: Nat + type family Add (m :: Nat) (n :: Nat) :: Nat + type family Pow (m :: Nat) (n :: Nat) :: Nat enumFamily mod ''Mod 10 + enumFamily (+) ''Add 10 + enumFamily (^) ''Pow 10 a :: Integer a = natVal (Proxy :: Proxy (Mod 6 4)) + -- 2 b :: Integer diff --git a/src/31-template-haskell/example.cabal b/src/31-template-haskell/example.cabal new file mode 100644 index 0000000..2a18243 --- /dev/null +++ b/src/31-template-haskell/example.cabal @@ -0,0 +1,20 @@ +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2016 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +tested-with: GHC ==7.6.3 +category: Documentation +build-type: Simple + +library + default-language: Haskell2010 + build-depends: + base >=4.6 && <4.14 + , derive >=2.6.5 && <2.7 + , language-c-quote >=0.12.2.1 && <0.13 + , mainland-pretty >=0.7.0.1 && <0.8 + , pretty-show >=1.10 && <1.11 + , QuickCheck >=2.13.2 && <2.14 + , singletons >=2.5.1 && <2.6 diff --git a/src/31-template-haskell/singleton_lib.hs b/src/31-template-haskell/singleton_lib.hs index 4376a04..da2a442 100644 --- a/src/31-template-haskell/singleton_lib.hs +++ b/src/31-template-haskell/singleton_lib.hs @@ -1,25 +1,34 @@ -{-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-} +{-# LANGUAGE EmptyCase #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE InstanceSigs #-} +{-# LANGUAGE KindSignatures #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE QuasiQuotes #-} -{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE UndecidableInstances #-} import Data.Singletons import Data.Singletons.TH -$(singletons [d| - data Nat = Zero | Succ Nat - deriving (Eq, Show) +$( singletons + [d| + data Nat = Zero | Succ Nat + deriving (Eq, Show) - plus :: Nat -> Nat -> Nat - plus Zero n = n - plus (Succ m) n = Succ (plus m n) + plus :: Nat -> Nat -> Nat + plus Zero n = n + plus (Succ m) n = Succ (plus m n) - isEven :: Nat -> Bool - isEven Zero = True - isEven (Succ Zero) = False - isEven (Succ (Succ n)) = isEven n - |]) + isEven :: Nat -> Bool + isEven Zero = True + isEven (Succ Zero) = False + isEven (Succ (Succ n)) = isEven n + |] + ) diff --git a/src/31-template-haskell/singleton_promote.hs b/src/31-template-haskell/singleton_promote.hs index 828e3a0..3ef76fb 100644 --- a/src/31-template-haskell/singleton_promote.hs +++ b/src/31-template-haskell/singleton_promote.hs @@ -1,28 +1,31 @@ -{-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE QuasiQuotes #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE UndecidableInstances #-} import Data.Singletons import Data.Singletons.TH -$(promote [d| - map :: (a -> b) -> [a] -> [b] - map _ [] = [] - map f (x:xs) = f x : map f xs - |]) +$( promote + [d| + map :: (a -> b) -> [a] -> [b] + map _ [] = [] + map f (x : xs) = f x : map f xs + |] + ) infixr 5 ::: -data HList (ts :: [ * ]) where +data HList (ts :: [*]) where Nil :: HList '[] (:::) :: t -> HList ts -> HList (t ': ts) @@ -34,17 +37,16 @@ type MapJust xs = Map Maybe xs -- mapJust :: [a] -> [Maybe a] mapJust :: HList xs -> HList (MapJust xs) mapJust Nil = Nil -mapJust (x ::: xs) = (Just x) ::: mapJust xs +mapJust (x ::: xs) = Just x ::: mapJust xs -type A = [Bool, String , Double , ()] +type A = [Bool, String, Double, ()] a :: HList A a = True ::: "foo" ::: 3.14 ::: () ::: Nil - example1 :: HList (MapJust A) example1 = mapJust a -- example1 reduces to example2 when expanded -example2 :: HList ([Maybe Bool, Maybe String , Maybe Double , Maybe ()]) +example2 :: HList [Maybe Bool, Maybe String, Maybe Double, Maybe ()] example2 = Just True ::: Just "foo" ::: Just 3.14 ::: Just () ::: Nil diff --git a/src/31-template-haskell/stack.yaml b/src/31-template-haskell/stack.yaml new file mode 100644 index 0000000..3604641 --- /dev/null +++ b/src/31-template-haskell/stack.yaml @@ -0,0 +1,10 @@ +resolver: lts-14.20 +packages: +- '.' +extra-deps: +- derive-2.6.5 +- haskell-src-exts-1.20.3 +- pretty-show-1.10 +- haskell-lexer-1.1 +flags: {} +extra-package-dbs: [] diff --git a/src/31-template-haskell/template_info.hs b/src/31-template-haskell/template_info.hs index 7a74920..73c0460 100644 --- a/src/31-template-haskell/template_info.hs +++ b/src/31-template-haskell/template_info.hs @@ -1,11 +1,11 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} -import Text.Show.Pretty (ppShow) import Language.Haskell.TH +import Text.Show.Pretty (ppShow) introspect :: Name -> Q Exp introspect n = do t <- reify n runIO $ putStrLn $ ppShow t - [| return () |] + [|return ()|] diff --git a/src/ci b/src/ci index ccc4348..e090d8a 100755 --- a/src/ci +++ b/src/ci @@ -103,7 +103,7 @@ echo -n "25-streaming .. " echo -e "\e[1;32mOK\e[0m" echo -n "26-data-formats .. " -(cd 25-data-formats && bash ci) +(cd 26-data-formats && bash ci) echo -e "\e[1;32mOK\e[0m" echo -n "27-web .. " From 8f5f3947e7eb815fe603fc5eb03c9624cf96cd7b Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 16:00:00 +0000 Subject: [PATCH 36/45] Get test suite passing --- src/32-cryptography/Pairing.hs | 7 ++++--- src/32-cryptography/ci | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100755 src/32-cryptography/ci diff --git a/src/32-cryptography/Pairing.hs b/src/32-cryptography/Pairing.hs index a717ed9..e869835 100644 --- a/src/32-cryptography/Pairing.hs +++ b/src/32-cryptography/Pairing.hs @@ -1,9 +1,10 @@ +{-# LANGUAGE OverloadedLists #-} + module Main where import Data.Curve.Weierstrass (Point (A), mul') import Data.Group (pow) import Data.Pairing.BN254 (BN254, G1, G2, pairing) -import Protolude p :: G1 BN254 p = @@ -23,9 +24,9 @@ q = main :: IO () main = do - putText "e(P, Q):" + putStrLn "e(P, Q):" print (pairing p q) - putText "e(P, Q) is bilinear:" + putStrLn "e(P, Q) is bilinear:" print $ pairing (mul' p a) (mul' q b) == pow (pairing p q) (a * b) where a = 2 :: Int diff --git a/src/32-cryptography/ci b/src/32-cryptography/ci new file mode 100755 index 0000000..8193a3b --- /dev/null +++ b/src/32-cryptography/ci @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e +stack build +stack exec ghc -- -e ":q" --interactive AES.hs +stack exec ghc -- -e ":q" --interactive Argon.hs +stack exec ghc -- -e ":q" --interactive Blake2.hs +stack exec ghc -- -e ":q" --interactive Curve25519.hs +stack exec ghc -- -e ":q" --interactive ECC.hs +stack exec ghc -- -e ":q" --interactive Ed25519.hs +stack exec ghc -- -e ":q" --interactive Galois.hs +stack exec ghc -- -e ":q" --interactive Keccak.hs +stack exec ghc -- -e ":q" --interactive Merkle.hs +stack exec ghc -- -e ":q" --interactive Pairing.hs +stack exec ghc -- -e ":q" --interactive Secp256k1.hs +stack exec ghc -- -e ":q" --interactive SHA.hs From cefd4205f34a86fc0c5eaaca6b8e04af0710ff38 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 16:28:14 +0000 Subject: [PATCH 37/45] Stack build --- src/14-interpreters/ci | 1 + 1 file changed, 1 insertion(+) diff --git a/src/14-interpreters/ci b/src/14-interpreters/ci index 65f5579..a5380e0 100755 --- a/src/14-interpreters/ci +++ b/src/14-interpreters/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive catamorphism.hs stack exec ghc -- -e ":q" --interactive factorial.hs stack exec ghc -- -e ":q" --interactive fext.hs From 25f4c79fa57a64e13fb54d505a3c4e27655ff295 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 16:36:44 +0000 Subject: [PATCH 38/45] Stack build --- src/15-testing/ci | 1 + src/16-type-families/ci | 1 + src/17-promotion/ci | 1 + src/18-generics/ci | 1 + src/24-parsing/ci | 1 + src/30-languages/ci | 1 + src/33-categories/ci | 1 + src/34-time/ci | 1 + 8 files changed, 8 insertions(+) diff --git a/src/15-testing/ci b/src/15-testing/ci index e1d560f..c9a3c4c 100755 --- a/src/15-testing/ci +++ b/src/15-testing/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive arbitrary.hs stack exec ghc -- -e ":q" --interactive criterion.hs stack exec ghc -- -e ":q" --interactive qcheck.hs diff --git a/src/16-type-families/ci b/src/16-type-families/ci index a5bc7d5..f05f09b 100755 --- a/src/16-type-families/ci +++ b/src/16-type-families/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive constraintkinds.hs stack exec ghc -- -e ":q" --interactive datafamily.hs stack exec ghc -- -e ":q" --interactive dict.hs diff --git a/src/17-promotion/ci b/src/17-promotion/ci index 2d458cd..1a214e6 100755 --- a/src/17-promotion/ci +++ b/src/17-promotion/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive closed_typefamily.hs stack exec ghc -- -e ":q" --interactive constraint_list.hs stack exec ghc -- -e ":q" --interactive countargs.hs diff --git a/src/18-generics/ci b/src/18-generics/ci index a7c3b9a..74681e3 100755 --- a/src/18-generics/ci +++ b/src/18-generics/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive biplate.hs stack exec ghc -- -e ":q" --interactive cereal.hs stack exec ghc -- -e ":q" --interactive data.hs diff --git a/src/24-parsing/ci b/src/24-parsing/ci index ed3e08f..a790b1f 100755 --- a/src/24-parsing/ci +++ b/src/24-parsing/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive attoparsec.hs stack exec ghc -- -e ":q" --interactive attoparsec_lang.hs stack exec ghc -- -e ":q" --interactive configurator.hs diff --git a/src/30-languages/ci b/src/30-languages/ci index e0f0899..1442dd6 100755 --- a/src/30-languages/ci +++ b/src/30-languages/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive haskelline.hs #stack exec ghc -- -e ":q" --interactive llvm-hs.hs stack exec ghc -- -e ":q" --interactive llvm-irbuilder.hs diff --git a/src/33-categories/ci b/src/33-categories/ci index 64d0c3f..df6affb 100755 --- a/src/33-categories/ci +++ b/src/33-categories/ci @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive categories.hs stack exec ghc -- -e ":q" --interactive dual.hs stack exec ghc -- -e ":q" --interactive functors.hs diff --git a/src/34-time/ci b/src/34-time/ci index fe40531..3ff3fef 100755 --- a/src/34-time/ci +++ b/src/34-time/ci @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +stack build stack exec ghc -- -e ":q" --interactive Strings.hs stack exec ghc -- -e ":q" --interactive Time.hs From 6337fe3692de669fb32b56bba142740c6cf081ec Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 16:54:24 +0000 Subject: [PATCH 39/45] Fix cabal bounds for vector --- src/16-type-families/example.cabal | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/16-type-families/example.cabal b/src/16-type-families/example.cabal index f491715..e38c043 100644 --- a/src/16-type-families/example.cabal +++ b/src/16-type-families/example.cabal @@ -1,16 +1,16 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2016 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 -tested-with: GHC == 7.6.3 +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - - build-depends: - base >= 4.6 && <4.14 - - default-language: Haskell2010 +library + default-language: Haskell2010 + build-depends: + base >=4.6 && <4.14 + , hashable >=1.2.0.0 && <1.4 + , unordered-containers >=0.2.10.0 && <0.3 + , vector >=0.11.0.0 && <0.13 From cc9d23c9e8c68565699f87e9b512406ffd636cb2 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 17:02:48 +0000 Subject: [PATCH 40/45] Add uniplate dependency --- src/18-generics/example.cabal | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/18-generics/example.cabal b/src/18-generics/example.cabal index 6c2b2e5..9d57647 100644 --- a/src/18-generics/example.cabal +++ b/src/18-generics/example.cabal @@ -1,13 +1,14 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2020 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 +cabal-version: >=1.10 +name: example +version: 0.1 +copyright: 2020 Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +author: Stephen Diehl +category: Documentation +build-type: Simple -library - default-language: Haskell2010 - build-depends: - base >= 4.6 && <4.14 +library + default-language: Haskell2010 + build-depends: + base >=4.6 && <4.14 + , uniplate >=1.6.12 && <1.7 From ea2b2d8ab269b68aec5b9fba95083e1f0344693f Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 17:12:00 +0000 Subject: [PATCH 41/45] Add cereal and aeson --- src/18-generics/example.cabal | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/18-generics/example.cabal b/src/18-generics/example.cabal index 9d57647..381ca70 100644 --- a/src/18-generics/example.cabal +++ b/src/18-generics/example.cabal @@ -10,5 +10,7 @@ build-type: Simple library default-language: Haskell2010 build-depends: - base >=4.6 && <4.14 - , uniplate >=1.6.12 && <1.7 + aeson + , base >=4.6 && <4.14 + , cereal >=0.5.8.1 && <0.6 + , uniplate >=1.6.12 && <1.7 From b3c98b034d4c7fcddea0d818ed8d2fbd6828154a Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 17:24:37 +0000 Subject: [PATCH 42/45] install blas --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 534bfff..a03c223 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ script: - stack $ARGS --no-terminal --install-ghc ghc includes.hs -- -o includes - stack $ARGS --no-terminal --install-ghc exec make html # Run the example test suite +- sudo apt-get install libblas liblapack - cd src && bash ./ci cache: directories: From 7e6a8eaa3cc76eaa0dedb4cb8c3a31d97b716eb3 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 17:36:22 +0000 Subject: [PATCH 43/45] Fix dependencies for blas --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a03c223..8318cad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ script: - stack $ARGS --no-terminal --install-ghc ghc includes.hs -- -o includes - stack $ARGS --no-terminal --install-ghc exec make html # Run the example test suite -- sudo apt-get install libblas liblapack +- sudo apt-get install libblas-dev liblapack-dev - cd src && bash ./ci cache: directories: From d34bd978b9b2d7e54776f8fd809ca9576b344345 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Wed, 26 Feb 2020 21:09:25 +0000 Subject: [PATCH 44/45] Async bounds --- src/22-concurrency/example.cabal | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/22-concurrency/example.cabal b/src/22-concurrency/example.cabal index cf6aeb7..fbe48b2 100644 --- a/src/22-concurrency/example.cabal +++ b/src/22-concurrency/example.cabal @@ -10,5 +10,6 @@ build-type: Simple library default-language: Haskell2010 build-depends: - base >=4.10 && <4.14, - monad-par >=0.3 && <0.4 + async >=2.2.2 && <2.3 + , base >=4.10 && <4.14 + , monad-par >=0.3 && <0.4 From f7e3cb845364f6dbf605fcfadfe1a95a9926b2e4 Mon Sep 17 00:00:00 2001 From: sdiehl Date: Thu, 27 Feb 2020 04:51:41 +0000 Subject: [PATCH 45/45] Bounds for criterion --- src/15-testing/example.cabal | 43 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/15-testing/example.cabal b/src/15-testing/example.cabal index 371e7d7..5d04c0b 100644 --- a/src/15-testing/example.cabal +++ b/src/15-testing/example.cabal @@ -1,24 +1,23 @@ -name: example -version: 0.1 -author: Stephen Diehl -maintainer: stephen.m.diehl@gmail.com -copyright: 2016 Stephen Diehl -category: Documentation -build-type: Simple -cabal-version: >=1.10 -tested-with: GHC == 7.6.3 +name: example +version: 0.1 +author: Stephen Diehl +maintainer: stephen.m.diehl@gmail.com +copyright: 2016 Stephen Diehl +category: Documentation +build-type: Simple +cabal-version: >=1.10 +tested-with: GHC ==7.6.3 -library +library + build-depends: + base >=4.6 && <4.14 + , criterion >=1.2 && <1.6 + , quickspec >=2.1 && <2.2 + , silently >=1.2 && <1.3 + , smallcheck >=1.1 && <1.2 + , tasty >=1.2 && <1.3 + , tasty-hunit >=0.9 && <0.11 + , tasty-quickcheck >=0.10 && <0.11 + , tasty-smallcheck >=0.8 && <0.9 - build-depends: - base >= 4.6 && <4.14, - tasty >= 1.2 && <1.3, - tasty-hunit >= 0.9 && <0.11, - tasty-quickcheck >= 0.10 && <0.11, - tasty-smallcheck >= 0.8 && <0.9, - silently >= 1.2 && <1.3, - quickspec >= 2.1 && <2.2, - smallcheck >= 1.1 && <1.2, - criterion -any - - default-language: Haskell2010 + default-language: Haskell2010