Skip to content

Instantly share code, notes, and snippets.

View safareli's full-sized avatar

Irakli Safareli safareli

View GitHub Profile

So church encoding of Piano numbers is like this:

type PianoC  = (z) -> (z -> z) -> z

zero just grabs "on zero handler" and returns that

zero :: PianoC
sum(1, 2, 3, 4) == 10 // true
sum(1, 2, 3, 4)(1, 2, 3, 4) == 20 // true
sum(1)(2)(3)(4)(1)(2)(3)(4) == 20 // true
function sum(...args) {
function res(...args2) {
return sum(_sum(args), _sum(args2))
}
// https://javascript.info/object-toprimitive
res[Symbol.toPrimitive] = () => _sum(args)
// prototype of making effect Readerish
// https://gist.github.com/safareli/7f60873324cce8880fb4cfa85defe4df
export interface EffectRaw<E,A> { (env: E): A }
interface EffectPURE<E, A> extends EffectRaw<E,A> {
tag: "PURE",
_0: A
}
interface EffectMAP<E, Z, A> extends EffectRaw<E, A>, EffectMAP_OP<Z, A> {
// modified from https://github.com/safareli/purescript-effect/blob/fast/src/Effect.js
/*
A computation of type `Effect<a>` in runtime is represented by a function which when
invoked performs some effect and results some value of type `a`.
With trivial implementation of `Effect` we have an issue with stack usage, as on each `bind`
you create new function which increases size of stack needed to execute whole computation.
For example if you write `forever` recursively like this, stack will overflow:
``` purs
function forever(f: Effect<A>): Effect<never> = chain(f, _ => f)
```
data Count = One | Two | ThreeOrMore
type Datum = { count :: Count, char :: Char }
data Stat = Stat (Array Datum)
instance semigroupCount :: Semigroup Count where
append One One = Two
append One _ = ThreeOrMore
append Two _ = ThreeOrMore
@safareli
safareli / SProxies.purs
Last active July 17, 2019 19:26
SProxies
-- | This is module defines modified version `SProxies` and `mkSProxies` from [here][Row] ([depending on this][Utils]).
-- | That code was licensed with [Apache License 2.0][License]
-- |
-- | [Row] - https://github.com/thomashoneyman/purescript-halogen-formless/blob/55e2453f8e0d9169ec3cdccdd8cc09c0e289ffea/src/Formless/Transform/Row.purs#L61-L100
-- | [Utils] - https://github.com/thomashoneyman/purescript-halogen-formless/blob/55e2453f8e0d9169ec3cdccdd8cc09c0e289ffea/src/Formless/Internal/Transform.purs#L23-L35
-- | [License] - https://github.com/thomashoneyman/purescript-halogen-formless/blob/55e2453f8e0d9169ec3cdccdd8cc09c0e289ffea/LICENSE
module Type.SProxies
( SProxies
, SProxies'
, mkSProxies
@safareli
safareli / Try2.purs
Last active April 12, 2019 14:09 — forked from paulvictor/Try2.purs
Using a dictionary to decide a runtime implementation
module Try2 where
import Prelude
import Control.Monad.Rec.Class (forever)
import Data.Tuple (uncurry)
import Data.Tuple.Nested ((/\), type (/\))
import Effect (Effect)
import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect)

Keybase proof

I hereby claim:

  • I am safareli on github.
  • I am safareli (https://keybase.io/safareli) on keybase.
  • I have a public key ASCnE0_lExjtbFI8yipNyuIMZMkKpOKIvRoy4_ePSSE1gAo

To claim this, I am signing this object:

@safareli
safareli / untilNextAnimationFrame.purs
Created February 27, 2019 12:21
performs delay untill next animation frame using requestAnimationFrame
-- | performs delay untill next animation frame.
untilNextAnimationFrame :: Aff Unit
untilNextAnimationFrame = do
var <- AVar.empty
w <- liftEffect $ window
Aff.bracket
(liftEffect $ requestAnimationFrame (launchAff_ $ AVar.put unit var) w)
(\requestAnimationFrameId -> liftEffect $ cancelAnimationFrame requestAnimationFrameId w)
(\_ -> AVar.take var)