summaryrefslogtreecommitdiff
path: root/Haskell-book/05/src
diff options
context:
space:
mode:
Diffstat (limited to 'Haskell-book/05/src')
-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
5 files changed, 120 insertions, 0 deletions
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))