Add the haskell book

This commit is contained in:
2025-12-09 16:32:32 +01:00
parent c95abc31d6
commit 3624c712d7
67 changed files with 1576 additions and 0 deletions

8
Haskell-book/05/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
/bower_components/
/node_modules/
/.pulp-cache/
/output/
/generated-docs/
/.psc*
/.purs*
/.psa*

View File

@@ -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"
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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))

View File

@@ -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."