Skip to content

Commit

Permalink
rewriting ex.3.1 page 41
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasios Valtinos committed Oct 31, 2022
1 parent 1539386 commit 6042f8e
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 8 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
(major1) == 4 && (major2) < 16 || \
(major1) == 4 && (major2) == 16 && (minor) <= 0)
#endif /* MIN_VERSION_base */
/* package mtl-2.2.2 */
#ifndef VERSION_mtl
#define VERSION_mtl "2.2.2"
#endif /* VERSION_mtl */
#ifndef MIN_VERSION_mtl
#define MIN_VERSION_mtl(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 2 || \
(major1) == 2 && (major2) == 2 && (minor) <= 2)
#endif /* MIN_VERSION_mtl */

/* tool gcc-10.2.0 */
#ifndef TOOL_VERSION_gcc
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cabal-version":"3.6.2.0","cabal-lib-version":"3.6.2.0","compiler-id":"ghc-9.2.1","os":"windows","arch":"x86_64","install-plan":[{"type":"pre-existing","id":"base-4.16.0.0","pkg-name":"base","pkg-version":"4.16.0.0","depends":["ghc-bignum-1.2","ghc-prim-0.8.0","rts-1.0.2"]},{"type":"pre-existing","id":"ghc-bignum-1.2","pkg-name":"ghc-bignum","pkg-version":"1.2","depends":["ghc-prim-0.8.0"]},{"type":"pre-existing","id":"ghc-prim-0.8.0","pkg-name":"ghc-prim","pkg-version":"0.8.0","depends":["rts-1.0.2"]},{"type":"configured","id":"parsing-0.1.0.0-inplace","pkg-name":"parsing","pkg-version":"0.1.0.0","flags":{},"style":"local","pkg-src":{"type":"local","path":"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Alejandro - Book of Monads\\."},"dist-dir":"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Alejandro - Book of Monads\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\parsing-0.1.0.0","depends":["base-4.16.0.0"],"exe-depends":[],"component-name":"lib"},{"type":"pre-existing","id":"rts-1.0.2","pkg-name":"rts","pkg-version":"1.0.2","depends":[]}]}
{"cabal-version":"3.6.2.0","cabal-lib-version":"3.6.2.0","compiler-id":"ghc-9.2.1","os":"windows","arch":"x86_64","install-plan":[{"type":"pre-existing","id":"base-4.16.0.0","pkg-name":"base","pkg-version":"4.16.0.0","depends":["ghc-bignum-1.2","ghc-prim-0.8.0","rts-1.0.2"]},{"type":"pre-existing","id":"ghc-bignum-1.2","pkg-name":"ghc-bignum","pkg-version":"1.2","depends":["ghc-prim-0.8.0"]},{"type":"pre-existing","id":"ghc-prim-0.8.0","pkg-name":"ghc-prim","pkg-version":"0.8.0","depends":["rts-1.0.2"]},{"type":"pre-existing","id":"mtl-2.2.2","pkg-name":"mtl","pkg-version":"2.2.2","depends":["base-4.16.0.0","transformers-0.5.6.2"]},{"type":"configured","id":"parsing-0.1.0.0-inplace","pkg-name":"parsing","pkg-version":"0.1.0.0","flags":{},"style":"local","pkg-src":{"type":"local","path":"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Alejandro - Book of Monads\\."},"dist-dir":"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Alejandro - Book of Monads\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\parsing-0.1.0.0","depends":["base-4.16.0.0","mtl-2.2.2"],"exe-depends":[],"component-name":"lib"},{"type":"pre-existing","id":"rts-1.0.2","pkg-name":"rts","pkg-version":"1.0.2","depends":[]},{"type":"pre-existing","id":"transformers-0.5.6.2","pkg-name":"transformers","pkg-version":"0.5.6.2","depends":["base-4.16.0.0"]}]}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data-dir:

hs-libraries: HSparsing-0.1.0.0-inplace
include-dirs: C:\tools\msys64\mingw64\include
depends: base-4.16.0.0
depends: base-4.16.0.0 mtl-2.2.2
haddock-interfaces:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Alejandro - Book of Monads\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\parsing-0.1.0.0\\doc\\html\\parsing\\parsing.haddock"

Expand Down
13 changes: 13 additions & 0 deletions Haskell Excercises & Code/Alejandro - Book of Monads/monadic.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{-# LANGUAGE FlexibleContexts #-}
module MonadicCode where

import Control.Monad.State as CMS


-- implement `ap` yourself

ap :: Monad m => m (a -> b) -> m a -> m b
ap mf mx = do
f <- mf
x <- mx
return (f x)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ library
exposed-modules: JSONParser
ghc-options: -Wall -fwarn-tabs
build-depends: base >=4.7 && <5
, mtl
hs-source-dirs: .
default-language: Haskell2010
14 changes: 8 additions & 6 deletions Haskell Excercises & Code/Alejandro - Book of Monads/practice.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module WithCounting where

import Control.Monad.State as CMS

-- Chapter 1. Exercises and Practice
type WithCounter a = Int -> (a, Int)

Expand All @@ -23,10 +25,10 @@ pure x = \i -> (x, i)
type State s a = s -> (a, s)

-- rewrite next & pure
next' :: State s a -> (a -> State s b) -> State s b
next' :: CMS.State s a -> (a -> CMS.State s b) -> CMS.State s b
f `next'` g = \i -> let (r, i') = f i in g r i'

pure' :: a -> State s a
pure' :: a -> CMS.State s a
pure' x = \s -> (x, s)

-- 1.2
Expand Down Expand Up @@ -54,7 +56,7 @@ flatten :: Maybe (Maybe a) -> Maybe a
flatten (Just (Just x)) = Just x
flatten _ = Nothing

flatten' oo = then_ oo id
-- case oo of
Nothing -> Nothing
Just x -> id x ==> x
-- flatten' oo = then_ oo id
-- -- case oo of
-- Nothing -> Nothing
-- Just x -> id x ==> x

0 comments on commit 6042f8e

Please sign in to comment.