This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- watch video https://www.youtube.com/watch?v=YyT1vLinnFk&t=353s | |
| import PrettyT | |
| import Data.List | |
| -- data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show | |
| equal :: Eq a => Btree a -> Btree a -> Bool | |
| equal Empty Empty = True | |
| equal Empty (Node _ _ _) = False | |
| equal (Node _ _ _) Empty = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- subscribe my channel https://www.youtube.com/channel/UCBGYk5s1Fnk0PpqSwtH1M9w | |
| -- https://gist.github.com/evgenii-malov/1fc29a652751451dbca0d54d454cc1ef | |
| import PrettyT | |
| import Data.List | |
| -- IMPORTANT NOTE: nodes must be uniq! | |
| -- data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show | |
| ino Empty = [] | |
| ino (Node a l r) = (ino l) ++ [a] ++ (ino r) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- subscribe my channel https://www.youtube.com/channel/UCBGYk5s1Fnk0PpqSwtH1M9w | |
| -- https://gist.github.com/evgenii-malov/1fc29a652751451dbca0d54d454cc1ef | |
| import PrettyT | |
| -- data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show | |
| paths :: Btree a -> [[a]] | |
| paths Empty = [] | |
| paths (Node a Empty Empty) = [[a]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- GHCi, version 8.8.4 | |
| -- author evgenii malov | |
| -- binary search tree - | |
| -- for every node the all left subtree nodes < and all right subtree node >= | |
| -- data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show | |
| import Data.List | |
| import PrettyT | |
| -- https://gist.github.com/evgenii-malov/1fc29a652751451dbca0d54d454cc1ef | |
| -- insert | |
| -- https://www.youtube.com/watch?v=TC9YPLyTTDo&t=0s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- see https://www.youtube.com/watch?v=6OD_lNIPp7w | |
| -- and https://stackoverflow.com/questions/70002842/expand-list-of-lists-by-adding-element-once-to-every-list/70221844#70221844 | |
| main = undefined | |
| class Eachable e where | |
| each :: (a -> a) -> e a -> [e a] | |
| instance Eachable [] where | |
| each _ [] = [] | |
| each g (x:xs) = ((g x) : xs) : map (x:) (each g xs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Concurrency python vs haskell, why haskell do it better? | |
| # see video - https://www.youtube.com/watch?v=5RBxI1fm6wA | |
| #python 3.10.0 | |
| #server | |
| import asyncio | |
| async def factorial(n): | |
| fact = 1 | |
| i = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Concurrency python vs haskell, why haskell do it better? | |
| -- see video - https://www.youtube.com/watch?v=5RBxI1fm6wA | |
| -- stack --resolver nightly-2021-11-27 new simpleserver | |
| -- dependencies: | |
| -- - base >= 4.7 && < 5 | |
| -- - network | |
| -- - bytestring | |
| -- - binary | |
| -- - monad-loops |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad | |
| -- [1,2] | |
| -- [ [[1],[2]],[[1,2]] ] | |
| -- [1,2,3] | |
| -- 3 [ [[3],[1],[2]],[[3,1],[2]],[[1],[3,2]], [[3],[1,2]],[[3,1,2]] ] | |
| -- [1,2] | |
| -- [ [[1],[2]],[[1,2]] ] | |
| --3 [[1],[2]] --> [ [[3,1],[2]], [[1],[3,2]] ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Applicative | |
| crt xs = do | |
| x <- xs | |
| y <- xs | |
| return [x,y] | |
| --cr xs = (,) <$> xs <*> xs | |
| -- cr xs = liftA2 (,) xs xs | |
| --cr xs = liftA2 (\x y -> [x,y]) xs xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List | |
| p :: Eq a => [a] -> [[a]] | |
| p [] = [[]] | |
| p xs = xs >>= (\x -> (x:) <$> p (delete x xs) ) |