Initial call
bounce(append(List(1,2,3,4,5),List(6)))
Descend into argument
append(List(1,2,3,4,5),List(6))
bounce(...)
| " Disable cursor blink so I can freely cut, splice and vary the speed of the screencast. | |
| set guicursor+=a:blinkon0 | |
| " Get rid of toolbar and scrollbars. | |
| set guioptions-=T | |
| set guioptions-=L | |
| set guioptions-=r | |
| set background=dark |
| # ... | |
| if [ -f ~/.gpg-agent-info ]; then | |
| . ~/.gpg-agent-info | |
| export GPG_AGENT_INFO | |
| fi | |
| # ... |
| import Data.Set.Monad as SM | |
| import Debug.Trace as DT | |
| (<+>) = liftM . plus | |
| plus x y = DT.trace "." (x + y) | |
| l = SM.fromList [0,1] | |
| -- Intuitively expect 28 additions, but we actually get 60! | |
| test = Set Int |
Initial call
bounce(append(List(1,2,3,4,5),List(6)))
Descend into argument
append(List(1,2,3,4,5),List(6))
bounce(...)
Learning about trampolining in Scala.
I began with Ken Scambler's [YOW! Lambda Jam 2014 workshop][ws] on Free monads, but found that the simple formulation of Free derived in [exercise 1][ex1] was susceptible to stack overflow when used for trampolining in [exercise 2][ex2]. This is just an investigation into what causes this stack overflow, and how [scalaz][]'s [GoSub][] trick avoids it.
| -- Is Set.union better than O(n+m) in some cases? | |
| import Criterion.Main (Benchmark, bench, bgroup, defaultMain, env, whnf) | |
| import Data.Set (Set, fromList, union) | |
| main :: IO () | |
| main = defaultMain [ bgroup "union" $ map benchUnion sizes ] | |
| -- Grow Set size exponentially, under the hypothesis that | |
| -- Set.union will be O(log n) in this special case. |
| import Criterion.Main (Benchmark, bench, bgroup, defaultMain, env, whnf) | |
| import Data.Foldable (Foldable(..),toList) | |
| import Data.Maybe (Maybe(..)) | |
| import Data.Monoid (Monoid(..), (<>)) | |
| import Data.Set (Set,fromList) | |
| import Prelude (Eq(..),Ord(..),Show(..),Int,(.),($),($!),Num(..),const,take,iterate,map,return,IO) | |
| last :: Foldable t => t a -> Maybe a | |
| last = foldl (const Just) Nothing |
| {-# LANGUAGE Rank2Types #-} | |
| type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t) | |
| type Ref s t a b = s -> Rep a b t | |
| data Rep a b t = Rep a (b -> t) | |
| instance Functor (Rep a b) where | |
| fmap f (Rep a g) = Rep a (f . g) |
| {-# LANGUAGE DeriveFoldable #-} | |
| {-# LANGUAGE DeriveFunctor #-} | |
| {-# LANGUAGE DeriveTraversable #-} | |
| {-# LANGUAGE ImpredicativeTypes #-} | |
| {-# LANGUAGE Rank2Types #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| -- Richard Bird, Thinking Functionally with Haskell. | |
| -- Chapter 2, Exercise E: |