Skip to content

Instantly share code, notes, and snippets.

Avatar

Irakli Safareli safareli

View GitHub Profile
View church-defunctionalization.md

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
View sum_infinit.js
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)
View ReaderEffect.ts
// 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> {
View Effect.ts
// 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)
```
View threeCharCombine.purs
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
View SProxies.purs
-- | 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 Apr 12, 2019 — forked from paulvictor/Try2.purs
Using a dictionary to decide a runtime implementation
View Try2.purs
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)
View keybase.md

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 Feb 27, 2019
performs delay untill next animation frame using requestAnimationFrame
View untilNextAnimationFrame.purs
-- | 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)
You can’t perform that action at this time.