summaryrefslogtreecommitdiff
path: root/Haskell-book/05
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-12-09 16:32:32 +0100
committerEugen Wissner <belka@caraus.de>2025-12-09 16:32:32 +0100
commit3624c712d72d246f21d4e710cec7c11e052e0326 (patch)
treef385cb51c72a0c5eeb2057609b75f5f8c6c4f272 /Haskell-book/05
parentc95abc31d62e296db4f1b537e3de440dd40defd1 (diff)
downloadbook-exercises-3624c712d72d246f21d4e710cec7c11e052e0326.tar.gz
Add the haskell book
Diffstat (limited to 'Haskell-book/05')
-rw-r--r--Haskell-book/05/.gitignore8
-rw-r--r--Haskell-book/05/bower.json21
-rw-r--r--Haskell-book/05/src/Arith3Broken.purs14
-rw-r--r--Haskell-book/05/src/Ex.purs36
-rw-r--r--Haskell-book/05/src/Main.purs9
-rw-r--r--Haskell-book/05/src/Sing.purs14
-rw-r--r--Haskell-book/05/src/TypeKwonDo.purs47
-rw-r--r--Haskell-book/05/test/Main.purs9
8 files changed, 158 insertions, 0 deletions
diff --git a/Haskell-book/05/.gitignore b/Haskell-book/05/.gitignore
new file mode 100644
index 0000000..9623fa5
--- /dev/null
+++ b/Haskell-book/05/.gitignore
@@ -0,0 +1,8 @@
+/bower_components/
+/node_modules/
+/.pulp-cache/
+/output/
+/generated-docs/
+/.psc*
+/.purs*
+/.psa*
diff --git a/Haskell-book/05/bower.json b/Haskell-book/05/bower.json
new file mode 100644
index 0000000..e443dfd
--- /dev/null
+++ b/Haskell-book/05/bower.json
@@ -0,0 +1,21 @@
+{
+ "name": "05",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "output"
+ ],
+ "dependencies": {
+ "purescript-prelude": "^3.1.0",
+ "purescript-console": "^3.0.0",
+ "purescript-tuples": "^4.1.0",
+ "purescript-strings": "^3.3.1",
+ "purescript-arrays": "^4.2.1",
+ "purescript-lists": "^4.10.0",
+ "purescript-unsafe-coerce": "^3.0.0"
+ },
+ "devDependencies": {
+ "purescript-psci-support": "^3.0.0"
+ }
+}
diff --git a/Haskell-book/05/src/Arith3Broken.purs b/Haskell-book/05/src/Arith3Broken.purs
new file mode 100644
index 0000000..e3938a4
--- /dev/null
+++ b/Haskell-book/05/src/Arith3Broken.purs
@@ -0,0 +1,14 @@
+-- arith3broken.hs
+module Arith3Broken where
+
+import Prelude
+import Control.Monad.Eff (Eff)
+import Control.Monad.Eff.Console (CONSOLE, log)
+
+main :: forall e. Eff (console :: CONSOLE | e) Unit
+main = do
+ log $ show (1 + 5)
+ log "10"
+ log $ show (negate $ -1)
+ log $ show ((+) 0 blah)
+ where blah = negate 1
diff --git a/Haskell-book/05/src/Ex.purs b/Haskell-book/05/src/Ex.purs
new file mode 100644
index 0000000..b075de4
--- /dev/null
+++ b/Haskell-book/05/src/Ex.purs
@@ -0,0 +1,36 @@
+module Ex where
+
+import Data.Array (head)
+import Data.Maybe (Maybe)
+import Data.Tuple (Tuple(..))
+import Prelude
+
+functionH :: forall a. Array a -> Maybe a
+functionH x = head x
+
+functionC :: forall a. Ord a => a -> a -> Boolean
+functionC x y = if (x > y) then true else false
+
+functionS :: forall a b. Tuple a b -> b
+functionS (Tuple x y) = y
+
+i :: forall a. a -> a
+i x = x
+
+c :: forall a b. a -> b -> a
+c x _ = x
+
+c'' :: forall a b. b -> a -> b
+c'' x _ = x
+
+c' :: forall a b. a -> b -> b
+c' _ y = y
+
+r :: forall a. Array a -> Array a
+r x = x
+
+co :: forall a b c. (b -> c) -> (a -> b) -> a -> c
+co f f' x = f $ f' x
+
+a :: forall a c. (a -> c) -> a -> a
+a _ x = x
diff --git a/Haskell-book/05/src/Main.purs b/Haskell-book/05/src/Main.purs
new file mode 100644
index 0000000..5674f56
--- /dev/null
+++ b/Haskell-book/05/src/Main.purs
@@ -0,0 +1,9 @@
+module Main where
+
+import Prelude
+import Control.Monad.Eff (Eff)
+import Control.Monad.Eff.Console (CONSOLE)
+import Arith3Broken as Arith3Broken
+
+main :: forall e. Eff (console :: CONSOLE | e) Unit
+main = Arith3Broken.main
diff --git a/Haskell-book/05/src/Sing.purs b/Haskell-book/05/src/Sing.purs
new file mode 100644
index 0000000..2ca173e
--- /dev/null
+++ b/Haskell-book/05/src/Sing.purs
@@ -0,0 +1,14 @@
+module Sing where
+
+import Prelude
+
+fstString :: String -> String
+fstString x = x <> " in the rain"
+
+sndString :: String -> String
+sndString x = x <> " over the rainbow"
+
+sing :: String
+sing = if (x > y) then fstString x else sndString y
+ where x = "Singin"
+ y = "Somewhere"
diff --git a/Haskell-book/05/src/TypeKwonDo.purs b/Haskell-book/05/src/TypeKwonDo.purs
new file mode 100644
index 0000000..9948502
--- /dev/null
+++ b/Haskell-book/05/src/TypeKwonDo.purs
@@ -0,0 +1,47 @@
+module TypeKwonDo where
+
+import Data.Tuple (Tuple(..), fst)
+import Prelude
+import Unsafe.Coerce (unsafeCoerce)
+
+f :: Int -> String
+f = unsafeCoerce unit
+
+g :: String -> Char
+g = unsafeCoerce unit
+
+h :: Int -> Char
+h x = g $ f x
+
+data A
+data B
+data C
+
+q :: A -> B
+q = unsafeCoerce unit
+
+w :: B -> C
+w = unsafeCoerce unit
+
+e :: A -> C
+e x = w $ q x
+
+data X
+data Y
+data Z
+
+xz :: X -> Z
+xz = unsafeCoerce unit
+
+yz :: Y -> Z
+yz = unsafeCoerce unit
+
+xform :: Tuple X Y -> Tuple Z Z
+xform (Tuple a b) = Tuple (xz a) (yz b)
+
+munge :: forall x y z w.
+ (x -> y)
+ -> (y -> (Tuple w z))
+ -> x
+ -> w
+munge f1 f2 a = fst (f2 (f1 a))
diff --git a/Haskell-book/05/test/Main.purs b/Haskell-book/05/test/Main.purs
new file mode 100644
index 0000000..845d0f4
--- /dev/null
+++ b/Haskell-book/05/test/Main.purs
@@ -0,0 +1,9 @@
+module Test.Main where
+
+import Prelude
+import Control.Monad.Eff (Eff)
+import Control.Monad.Eff.Console (CONSOLE, log)
+
+main :: forall e. Eff (console :: CONSOLE | e) Unit
+main = do
+ log "You should add some tests."