layout: blog title: Explore Memoization date: 2019-07-18T16:20:16.898Z author: Toan Nguyen Gia authorAvatar: /img/uploads/t0d8dq73q-u9hr7hu1m-706d3758d60e-512.jpeg image: /img/uploads/deco-iskusstvoa-helix.jpg tags:
- Tech
- Javascript
layout: blog title: Explore Memoization date: 2019-07-18T16:20:16.898Z author: Toan Nguyen Gia authorAvatar: /img/uploads/t0d8dq73q-u9hr7hu1m-706d3758d60e-512.jpeg image: /img/uploads/deco-iskusstvoa-helix.jpg tags:
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| open Relude.Globals; | |
| module R = Relude; | |
| let (>>=) = IO.(>>=); | |
| let fetchPostById: string => IO.t(string, string) = | |
| id => | |
| Fetch.fetch("https://jsonplaceholder.typicode.com/posts/" ++ id) | |
| |> Js.Promise.then_(Fetch.Response.text) |
"A phantom type is a parametrised type whose parameters do not all appear on the right-hand side of its definition..." Haskell Wiki, PhantomType
The following write-up is intended as an introduction into using phantom types in ReasonML.
Taking a look at the above definition from the Haskell wiki, it states that phantom types are parametrised types where not all parameters appear on the right-hand side. Let's try to see if we can implement a similar example as in said wiki.
brew tap mopidy/mopidy
brew install mopidy
| . . | |
| ';;,. ::' | |
| ,:::;,,' :ccc, | |
| ,::c::,,,,. :cccc, | |
| ,cccc:;;;;;. cllll, | |
| ,cccc;.;;;;;, cllll; | |
| ;cccc; .;;;;;;. coooo; | |
| ;llll; ,:::::'loooo; | |
| ;llll: ':::::loooo: | |
| :oooo: .::::llodd: |
| /* | |
| * Cold observable: | |
| * produce values upon each subscription | |
| */ | |
| const coldObs$ = Rx.Observable.interval(1000) | |
| /* | |
| * Warm observable: | |
| * share the value source to all subscriptions, |