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
| #!/usr/bin/env stack | |
| {- stack | |
| --resolver lts-16.26 | |
| --install-ghc | |
| exec ghci | |
| --package http-client | |
| -} | |
| {-# LANGUAGE LambdaCase #-} | |
| {-# LANGUAGE NoImplicitPrelude #-} |
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
| #!/usr/bin/env stack | |
| {- stack | |
| --resolver lts-16.8 | |
| --install-ghc | |
| exec ghci | |
| --package connection | |
| --package http-client | |
| --package http-client-tls | |
| -} |
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.Tree (Tree(Node, rootLabel, subForest)) | |
| paths :: Tree a -> [[a]] | |
| paths = \case | |
| Node { rootLabel, subForest } -> | |
| [rootLabel] : concatMap (map (rootLabel :) . paths) subForest |
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
| #!/usr/bin/env stack | |
| {- stack | |
| --resolver lts-16.8 | |
| --install-ghc | |
| exec ghci | |
| -} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| import Prelude hiding (foldl, foldr) |
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
| -- const has type: | |
| -- const :: a -> b -> a | |
| weirdConst :: b -> (forall a. a -> a) -> b | |
| weirdConst b _f = b | |
| blah :: Int | |
| blah = weirdConst 42 id | |
| -- blahBlah produces this compiler error: | |
| -- |
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
| #!/usr/bin/env stack | |
| -- stack --resolver lts-15.6 --install-ghc exec ghci --package wai | |
| {-# LANGUAGE ScopedTypeVariables, TypeApplications #-} | |
| import Network.Wai (Middleware) | |
| -- | This function doesn't look like much, but is pretty neat-o... | |
| h :: (Functor f) => (b -> c) -> (a -> f b) -> a -> f c | |
| h g f = fmap g . f |
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
| #!/usr/bin/env stack | |
| -- stack --resolver lts-15.6 script --package text | |
| {-# LANGUAGE NoImplicitPrelude #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| import Data.Text (Text) | |
| import Prelude | |
| import qualified Data.Text as Text | |
| import qualified Data.Text.IO as Text.IO |
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
| #!/usr/bin/env stack | |
| -- stack --resolver lts-16.3 --install-ghc exec ghci | |
| {-# OPTIONS_GHC -Wall -Werror #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| import Data.Set (Set) | |
| import qualified Data.Set as Set |
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
| printTree :: Show a => Tree a -> IO () | |
| printTree = putStrLn . Tree.drawTree . fmap show | |
| tree :: Tree Int | |
| tree = Tree.unfoldTree buildNode 1 where | |
| buildNode :: Int -> (Int, [Int]) | |
| buildNode n | |
| | 2 * n + 1 <= 7 = (n, [2 * n, 2 * n + 1]) | |
| | otherwise = (n, []) |