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
| // This gist shows how to factor a concrete stateful fold in vanilla JS | |
| // into a number of general purpose utilities that can be combined to recover | |
| // the original behavior | |
| // We're going to start from a particular code snippet and iteratively make | |
| // small changes to it to get a finished product | |
| // While reading this post, it is useful to have a diff tool at hand that allows | |
| // you to compare snippets side by side and see what changed in each iteration |
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 { adt, match, otherwise } = require("@masaeedu/adt"); | |
| const { | |
| Obj, | |
| Fn, | |
| Arr, | |
| Cont, | |
| implement, | |
| Functor, | |
| Apply, | |
| Chain, |
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
| :: :: morphism c = c -> c -> * | |
| :: :: morphism c -> * | |
| :: category p = | |
| :: { id: p a a, compose: p b c -> p a b -> p a c } | |
| :: :: (c -> d) -> morphism c -> morphism d -> * | |
| :: functor f i o = | |
| :: { map: i a b -> o (f a) (f b) } |
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
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE ViewPatterns #-} | |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| module Main where | |
| import Prelude as P |
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
| {-# LANGUAGE | |
| RankNTypes, | |
| TypeApplications, | |
| TypeOperators, | |
| KindSignatures, | |
| TypeFamilies, | |
| TypeInType, | |
| MultiParamTypeClasses, | |
| FunctionalDependencies, | |
| FlexibleInstances, |
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
| {-# LANGUAGE | |
| KindSignatures | |
| , DataKinds | |
| , RankNTypes | |
| , GADTs | |
| , TypeFamilies | |
| , TypeFamilyDependencies | |
| , ScopedTypeVariables | |
| , TypeApplications | |
| , ViewPatterns |
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
| module Test where | |
| import Prelude | |
| import Data.Lens (Lens, _Just, lens, (.~)) | |
| import Data.Maybe (Maybe(..)) | |
| import Effect.Exception.Unsafe (unsafeThrow) | |
| data CRUD a | |
| = Create |
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
| module ComonadKleisli where | |
| import Data.Maybe | |
| import Data.List | |
| import Control.Monad | |
| fmapM :: (a -> Maybe b) -> [a] -> Maybe [b] | |
| fmapM f = Just . catMaybes . fmap f | |
| duplicateM :: [a] -> Maybe [[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
| #!/usr/bin/env bash | |
| set -Eeuxo pipefail | |
| # Set up git | |
| git init | |
| gitignore haskell | |
| echo '*.cabal' >> .gitignore | |
| # Set up niv | |
| niv init |
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
| {-# LANGUAGE | |
| TypeOperators | |
| , RankNTypes | |
| , MultiParamTypeClasses | |
| , ConstraintKinds | |
| , QuantifiedConstraints | |
| , KindSignatures | |
| #-} | |
| module Main where |