progress
This commit is contained in:
parent
cc7ee03907
commit
250335f16b
10 changed files with 682 additions and 594 deletions
|
@ -2,13 +2,19 @@
|
||||||
Author: Yann Esposito
|
Author: Yann Esposito
|
||||||
*/
|
*/
|
||||||
/* Fonts */
|
/* Fonts */
|
||||||
|
:root {
|
||||||
|
--lh: 16px;
|
||||||
|
}
|
||||||
body {
|
body {
|
||||||
font: 14px/1.4 monospace;
|
font: 14px/1.4 monospace;
|
||||||
line-height: 16px;
|
line-height: var(--lh);
|
||||||
}
|
}
|
||||||
pre, pre code {
|
pre, pre code {
|
||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
}
|
}
|
||||||
|
blockquote pre {
|
||||||
|
line-height: var(--lh);
|
||||||
|
}
|
||||||
/* Layout */
|
/* Layout */
|
||||||
body, h1, h2, h3, h4, h5, h6, pre, code, blockquote, ol, ul, ol ol, ul ul, ul ol, ol
|
body, h1, h2, h3, h4, h5, h6, pre, code, blockquote, ol, ul, ol ol, ul ul, ul ol, ol
|
||||||
ul, li, p, section, header, footer, img {
|
ul, li, p, section, header, footer, img {
|
||||||
|
@ -20,8 +26,8 @@ ul, li, p, section, header, footer, img {
|
||||||
}
|
}
|
||||||
h1, h2, h3, h4, h5, h6, pre, code, blockquote, p, ul, ol, section, header,
|
h1, h2, h3, h4, h5, h6, pre, code, blockquote, p, ul, ol, section, header,
|
||||||
figure,table {
|
figure,table {
|
||||||
margin-top: 1em;
|
margin-top: var(--lh);
|
||||||
margin-bottom: 1em;
|
margin-bottom: var(--lh);
|
||||||
}
|
}
|
||||||
li {
|
li {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -122,7 +128,7 @@ hr {
|
||||||
margin:0;
|
margin:0;
|
||||||
}
|
}
|
||||||
#table-of-contents {
|
#table-of-contents {
|
||||||
margin-bottom: 1em;
|
margin-bottom: var(--lh);
|
||||||
}
|
}
|
||||||
#postamble:before, hr:after {
|
#postamble:before, hr:after {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -186,7 +192,7 @@ figure, .figure {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
#postamble {
|
#postamble {
|
||||||
margin-top: 1em;
|
margin-top: var(--lh);
|
||||||
}
|
}
|
||||||
.timestamp-wrapper {
|
.timestamp-wrapper {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
@ -252,9 +258,9 @@ figure, .figure {
|
||||||
@media (prefers-color-scheme: light) {
|
@media (prefers-color-scheme: light) {
|
||||||
:root {
|
:root {
|
||||||
--bg: var(--b3);
|
--bg: var(--b3);
|
||||||
--fg: var(--b00);
|
--fg: var(--b01);
|
||||||
--bg2: var(--b2);
|
--bg2: var(--b2);
|
||||||
--fg2: var(--b1);
|
--fg2: var(--b00);
|
||||||
--rfg: var(--b01);
|
--rfg: var(--b01);
|
||||||
--rbg: var(--b2);
|
--rbg: var(--b2);
|
||||||
--bdr: var(--b2);
|
--bdr: var(--b2);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fib :: [Integer]
|
fib :: [Integer]
|
||||||
fib = 1:1:zipWith (+) fib (tail fib)
|
fib = 1:1:zipWith (+) fib (tail fib)
|
||||||
|
|
||||||
main = traverse_ print (take 20 (drop 200 fib))
|
main = traverse print (take 20 (drop 200 fib))
|
||||||
|
|
11
src/posts/0010-Haskell-Now/fib_lazy_trace.hs
Normal file
11
src/posts/0010-Haskell-Now/fib_lazy_trace.hs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
|
-- like + but each time this is evaluated print a trace
|
||||||
|
tracedPlus x y = trace ("> " ++ show x ++ " + " ++ show y) (x + y)
|
||||||
|
|
||||||
|
fib :: [Integer]
|
||||||
|
fib = 1:1:zipWith tracedPlus fib (tail fib)
|
||||||
|
|
||||||
|
main = do
|
||||||
|
print (fib !! 10)
|
||||||
|
print (fib !! 12)
|
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,21 @@
|
||||||
import Data.Tree (Tree,Forest(..))
|
import Data.Tree (Tree,Forest(..))
|
||||||
import qualified Data.Tree as Tree
|
import qualified Data.Tree as Tree
|
||||||
|
|
||||||
data BinTree a = Empty
|
data BinTree a = Empty
|
||||||
| Node a (BinTree a) (BinTree a)
|
| Node a (BinTree a) (BinTree a)
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- | Function to transform our internal BinTree type to the
|
-- | Function to transform our internal BinTree type to the
|
||||||
-- type of Tree declared in Data.Tree (from containers package)
|
-- type of Tree declared in Data.Tree (from containers package)
|
||||||
-- so that the function Tree.drawForest can use
|
-- so that the function Tree.drawForest can use
|
||||||
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
||||||
binTreeToForestString Empty = []
|
binTreeToForestString Empty = []
|
||||||
binTreeToForestString (Node x left right) =
|
binTreeToForestString (Node x left right) =
|
||||||
[Tree.Node (show x) ((binTreeToForestString left) ++ (binTreeToForestString right))]
|
[Tree.Node (show x) ((binTreeToForestString left) ++ (binTreeToForestString right))]
|
||||||
|
|
||||||
-- | Function that given a BinTree print a representation of it in the console
|
-- | Function that given a BinTree print a representation of it in the console
|
||||||
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
||||||
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
||||||
|
|
||||||
nullTree = Node 0 nullTree nullTree
|
nullTree = Node 0 nullTree nullTree
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
import Data.Tree (Tree,Forest(..))
|
import Data.Tree (Tree,Forest(..))
|
||||||
import qualified Data.Tree as Tree
|
import qualified Data.Tree as Tree
|
||||||
|
|
||||||
data BinTree a = Empty
|
data BinTree a = Empty
|
||||||
| Node a (BinTree a) (BinTree a)
|
| Node a (BinTree a) (BinTree a)
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- | Function to transform our internal BinTree type to the
|
-- | Function to transform our internal BinTree type to the
|
||||||
-- type of Tree declared in Data.Tree (from containers package)
|
-- type of Tree declared in Data.Tree (from containers package)
|
||||||
-- so that the function Tree.drawForest can use
|
-- so that the function Tree.drawForest can use
|
||||||
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
||||||
binTreeToForestString Empty = []
|
binTreeToForestString Empty = []
|
||||||
binTreeToForestString (Node x left right) =
|
binTreeToForestString (Node x left right) =
|
||||||
[Tree.Node (show x) ((binTreeToForestString left) ++ (binTreeToForestString right))]
|
[Tree.Node (show x) ((binTreeToForestString left) ++ (binTreeToForestString right))]
|
||||||
|
|
||||||
-- | Function that given a BinTree print a representation of it in the console
|
-- | Function that given a BinTree print a representation of it in the console
|
||||||
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
||||||
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
||||||
|
|
||||||
-- | take all element of a BinTree up to some depth
|
-- | take all element of a BinTree up to some depth
|
||||||
treeTakeDepth _ Empty = Empty
|
treeTakeDepth _ Empty = Empty
|
||||||
treeTakeDepth 0 _ = Empty
|
treeTakeDepth 0 _ = Empty
|
||||||
treeTakeDepth n (Node x left right) = let
|
treeTakeDepth n (Node x left right) = let
|
||||||
nl = treeTakeDepth (n-1) left
|
nl = treeTakeDepth (n-1) left
|
||||||
nr = treeTakeDepth (n-1) right
|
nr = treeTakeDepth (n-1) right
|
||||||
in
|
in
|
||||||
|
|
19
src/posts/0010-Haskell-Now/io_sum_ask.hs
Normal file
19
src/posts/0010-Haskell-Now/io_sum_ask.hs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import Data.Maybe
|
||||||
|
import Text.Read (readMaybe)
|
||||||
|
|
||||||
|
getListFromString :: String -> Maybe [Integer]
|
||||||
|
getListFromString str = readMaybe $ "[" ++ str ++ "]"
|
||||||
|
|
||||||
|
askUser :: IO [Integer]
|
||||||
|
askUser = do
|
||||||
|
putStrLn "Enter a list of numbers (separated by comma):"
|
||||||
|
input <- getLine
|
||||||
|
let maybeList = getListFromString input
|
||||||
|
case maybeList of
|
||||||
|
Just l -> return l
|
||||||
|
Nothing -> askUser
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
list <- askUser
|
||||||
|
print $ sum list
|
|
@ -1,18 +1,14 @@
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Text.Read (readMaybe)
|
||||||
maybeRead :: Read a => String -> Maybe a
|
|
||||||
maybeRead s = case reads s of
|
|
||||||
[(x,"")] -> Just x
|
|
||||||
_ -> Nothing
|
|
||||||
|
|
||||||
getListFromString :: String -> Maybe [Integer]
|
getListFromString :: String -> Maybe [Integer]
|
||||||
getListFromString str = maybeRead $ "[" ++ str ++ "]"
|
getListFromString str = readMaybe $ "[" ++ str ++ "]"
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
putStrLn "Enter a list of numbers (separated by comma):"
|
putStrLn "Enter a list of numbers (separated by comma):"
|
||||||
input <- getLine
|
input <- getLine
|
||||||
let maybeList = getListFromString input in
|
let maybeList = getListFromString input
|
||||||
case maybeList of
|
case maybeList of
|
||||||
Just l -> print (sum l)
|
Just l -> print (sum l)
|
||||||
Nothing -> putStrLn "Bad format. Good Bye."
|
Nothing -> putStrLn "Bad format. Good Bye."
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
{ nixpkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }:
|
{ nixpkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }:
|
||||||
let
|
let
|
||||||
inherit (nixpkgs) pkgs;
|
inherit (nixpkgs) pkgs;
|
||||||
inherit (pkgs) haskellPackages;
|
inherit (pkgs) haskellPackages;
|
||||||
|
|
||||||
haskellDeps = ps: with ps; [
|
haskellDeps = ps: with ps; [
|
||||||
base
|
base
|
||||||
protolude
|
protolude
|
||||||
|
containers
|
||||||
];
|
];
|
||||||
|
|
||||||
ghc = haskellPackages.ghcWithPackages haskellDeps;
|
ghc = haskellPackages.ghcWithPackages haskellDeps;
|
||||||
|
@ -15,11 +16,11 @@ let
|
||||||
pkgs.gdb
|
pkgs.gdb
|
||||||
haskellPackages.cabal-install
|
haskellPackages.cabal-install
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
pkgs.stdenv.mkDerivation {
|
||||||
name = "env";
|
name = "env";
|
||||||
buildInputs = nixPackages;
|
buildInputs = nixPackages;
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
export PS1="\n[hs:\033[1;32m\]\W\[\033[0m\]]> "
|
export PS1="\n[hs:\033[1;32m\]\W\[\033[0m\]]> "
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
Loading…
Reference in a new issue