progress
This commit is contained in:
parent
cc7ee03907
commit
250335f16b
|
@ -2,13 +2,19 @@
|
|||
Author: Yann Esposito
|
||||
*/
|
||||
/* Fonts */
|
||||
:root {
|
||||
--lh: 16px;
|
||||
}
|
||||
body {
|
||||
font: 14px/1.4 monospace;
|
||||
line-height: 16px;
|
||||
line-height: var(--lh);
|
||||
}
|
||||
pre, pre code {
|
||||
line-height: 1em;
|
||||
}
|
||||
blockquote pre {
|
||||
line-height: var(--lh);
|
||||
}
|
||||
/* Layout */
|
||||
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 {
|
||||
|
@ -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,
|
||||
figure,table {
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
margin-top: var(--lh);
|
||||
margin-bottom: var(--lh);
|
||||
}
|
||||
li {
|
||||
display: block;
|
||||
|
@ -122,7 +128,7 @@ hr {
|
|||
margin:0;
|
||||
}
|
||||
#table-of-contents {
|
||||
margin-bottom: 1em;
|
||||
margin-bottom: var(--lh);
|
||||
}
|
||||
#postamble:before, hr:after {
|
||||
text-align: center;
|
||||
|
@ -186,7 +192,7 @@ figure, .figure {
|
|||
margin-top: 0;
|
||||
}
|
||||
#postamble {
|
||||
margin-top: 1em;
|
||||
margin-top: var(--lh);
|
||||
}
|
||||
.timestamp-wrapper {
|
||||
font-size: 12px;
|
||||
|
@ -252,9 +258,9 @@ figure, .figure {
|
|||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--bg: var(--b3);
|
||||
--fg: var(--b00);
|
||||
--fg: var(--b01);
|
||||
--bg2: var(--b2);
|
||||
--fg2: var(--b1);
|
||||
--fg2: var(--b00);
|
||||
--rfg: var(--b01);
|
||||
--rbg: var(--b2);
|
||||
--bdr: var(--b2);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
fib :: [Integer]
|
||||
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 qualified Data.Tree as Tree
|
||||
import Data.Tree (Tree,Forest(..))
|
||||
import qualified Data.Tree as Tree
|
||||
|
||||
data BinTree a = Empty
|
||||
data BinTree a = Empty
|
||||
| Node a (BinTree a) (BinTree a)
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
-- | Function to transform our internal BinTree type to the
|
||||
-- type of Tree declared in Data.Tree (from containers package)
|
||||
-- so that the function Tree.drawForest can use
|
||||
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
||||
binTreeToForestString Empty = []
|
||||
binTreeToForestString (Node x left right) =
|
||||
-- | Function to transform our internal BinTree type to the
|
||||
-- type of Tree declared in Data.Tree (from containers package)
|
||||
-- so that the function Tree.drawForest can use
|
||||
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
||||
binTreeToForestString Empty = []
|
||||
binTreeToForestString (Node x left right) =
|
||||
[Tree.Node (show x) ((binTreeToForestString left) ++ (binTreeToForestString right))]
|
||||
|
||||
-- | Function that given a BinTree print a representation of it in the console
|
||||
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
||||
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
||||
-- | Function that given a BinTree print a representation of it in the console
|
||||
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
||||
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
||||
|
||||
nullTree = Node 0 nullTree nullTree
|
||||
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
import Data.Tree (Tree,Forest(..))
|
||||
import qualified Data.Tree as Tree
|
||||
import Data.Tree (Tree,Forest(..))
|
||||
import qualified Data.Tree as Tree
|
||||
|
||||
data BinTree a = Empty
|
||||
data BinTree a = Empty
|
||||
| Node a (BinTree a) (BinTree a)
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
-- | Function to transform our internal BinTree type to the
|
||||
-- type of Tree declared in Data.Tree (from containers package)
|
||||
-- so that the function Tree.drawForest can use
|
||||
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
||||
binTreeToForestString Empty = []
|
||||
binTreeToForestString (Node x left right) =
|
||||
-- | Function to transform our internal BinTree type to the
|
||||
-- type of Tree declared in Data.Tree (from containers package)
|
||||
-- so that the function Tree.drawForest can use
|
||||
binTreeToForestString :: (Show a) => BinTree a -> Forest String
|
||||
binTreeToForestString Empty = []
|
||||
binTreeToForestString (Node x left right) =
|
||||
[Tree.Node (show x) ((binTreeToForestString left) ++ (binTreeToForestString right))]
|
||||
|
||||
-- | Function that given a BinTree print a representation of it in the console
|
||||
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
||||
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
||||
-- | Function that given a BinTree print a representation of it in the console
|
||||
prettyPrintTree :: (Show a) => BinTree a -> IO ()
|
||||
prettyPrintTree = putStrLn . Tree.drawForest . binTreeToForestString
|
||||
|
||||
-- | take all element of a BinTree up to some depth
|
||||
treeTakeDepth _ Empty = Empty
|
||||
treeTakeDepth 0 _ = Empty
|
||||
treeTakeDepth n (Node x left right) = let
|
||||
-- | take all element of a BinTree up to some depth
|
||||
treeTakeDepth _ Empty = Empty
|
||||
treeTakeDepth 0 _ = Empty
|
||||
treeTakeDepth n (Node x left right) = let
|
||||
nl = treeTakeDepth (n-1) left
|
||||
nr = treeTakeDepth (n-1) right
|
||||
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
|
||||
|
||||
maybeRead :: Read a => String -> Maybe a
|
||||
maybeRead s = case reads s of
|
||||
[(x,"")] -> Just x
|
||||
_ -> Nothing
|
||||
import Text.Read (readMaybe)
|
||||
|
||||
getListFromString :: String -> Maybe [Integer]
|
||||
getListFromString str = maybeRead $ "[" ++ str ++ "]"
|
||||
getListFromString str = readMaybe $ "[" ++ str ++ "]"
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "Enter a list of numbers (separated by comma):"
|
||||
input <- getLine
|
||||
let maybeList = getListFromString input in
|
||||
let maybeList = getListFromString input
|
||||
case maybeList of
|
||||
Just l -> print (sum l)
|
||||
Nothing -> putStrLn "Bad format. Good Bye."
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{ nixpkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }:
|
||||
let
|
||||
{ nixpkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }:
|
||||
let
|
||||
inherit (nixpkgs) pkgs;
|
||||
inherit (pkgs) haskellPackages;
|
||||
|
||||
haskellDeps = ps: with ps; [
|
||||
base
|
||||
protolude
|
||||
containers
|
||||
];
|
||||
|
||||
ghc = haskellPackages.ghcWithPackages haskellDeps;
|
||||
|
@ -15,11 +16,11 @@ let
|
|||
pkgs.gdb
|
||||
haskellPackages.cabal-install
|
||||
];
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "env";
|
||||
buildInputs = nixPackages;
|
||||
shellHook = ''
|
||||
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