Skip to content

Instantly share code, notes, and snippets.

@eric-corumdigital
eric-corumdigital / example.purs
Created March 8, 2018 15:16
PureScript Foreign Non-Plain Object Import
import foreign data XImpl :: Type
type X = { a :: Number, b :: Number, impl :: XImpl }
foreign import foo :: forall eff. Eff eff X
---
exports.foo = function() {
var x = doFoo();
@eric-corumdigital
eric-corumdigital / subscribeWithLast.purs
Created March 13, 2018 17:24
purescript-behaviors subscribeWithLast
subscribeWithLast :: forall a b eff.
(b -> a -> Eff (frp :: FRP | eff) b)
-> b
-> Event a
-> Eff (frp :: FRP | eff) (Eff (frp :: FRP | eff) b)
subscribeWithLast f z evt = dropRefEff $ do
r <- newRef z
unsub <-
FRP.subscribe evt
(\e -> readRef r >>= \a -> addRefEff (f a e) >>= writeRef r)
@eric-corumdigital
eric-corumdigital / incremental.purs
Created June 13, 2018 20:13
Incremental functions category draft (PS)
type Jet a = { position :: a, velocity :: Change a }
destination :: forall a da. Patch a da => Jet a -> a
destination {position, velocity} = patch position (fromChange velocity)
newtype Incremental a b = Incremental (Jet a -> Jet b)
-- | Construct an incremental function from a function on Jets. The user must
-- | verify that these laws hold:
-- |
newtype Catch e r a = Catch forall x
. ( forall n e s
. IsSymbol n
=> Row.Cons n (FProxy (Except e)) r s
=> SProxy n
-> Run s a
-> (e -> Run r a)
-> x
)
-> x
module Main where
import Data.NaturalTransformation (type (~>))
import Data.Symbol (class IsSymbol, SProxy)
import Prim.Row as Row
import Unsafe.Coerce (unsafeCoerce)
data VariantRF (s :: # Type) (r :: # Type) (a :: Type)
data RFProxy (f :: # Type -> Type -> Type) = RFProxy
@eric-corumdigital
eric-corumdigital / hlist.purs
Created August 10, 2018 15:07
PureScript HList
module Data.HList where
import Data.Semiring ((+))
import Prim.RowList (Cons, Nil, kind RowList)
import Type.Data.RowList (RLProxy)
import Type.Equality (class TypeEquals)
newtype HList (xs :: RowList) = HList forall r
. (forall y ys. TypeEquals (RLProxy xs) (RLProxy (Cons "" y ys)) => y -> HList ys -> r)
-> (TypeEquals (RLProxy xs) (RLProxy Nil) => r)
@eric-corumdigital
eric-corumdigital / lattices.purs
Last active March 13, 2019 20:06
Lattices in PureScript
foreign import kind Semilattice
foreign import data Meet ∷ Semilattice
foreign import data Join ∷ Semilattice
data SemilatticeProxy (s ∷ Semilattice) = SemilatticeProxy
class Semilattice (x ∷ Semilattice) a where
marry ∷ ∀ proxy. proxy x → a → a → a
@eric-corumdigital
eric-corumdigital / x.purs
Last active April 29, 2019 15:14
PureScript deriving newtype Number not of form
class (LeftModule v a, RightModule v a) ⇐ Bimodule v a
newtype Pixels = Pixels (Additive Number)
derive newtype instance bimodulePixels ∷ Bimodule Pixels Number
---
Cannot derive the type class instance
if (interrupt === null) {
switch (status) {
case SUSPEND: return util.stateSuspended;
case COMPLETED: return util.stateCompleted;
default: return util.stateRunning;
}
}
else {
switch (status) {
case COMPLETED: return util.stateKilled;
module FRIST-SYNTAX
syntax Expr ::= Expr "+" Expr [left, strict]
| "(" Expr ")" [bracket]
| Ident
syntax Ident ::= "x" | "y" | "z"
endmodule