Skip to content

Instantly share code, notes, and snippets.

View clinuxrulz's full-sized avatar

Clinton Selke clinuxrulz

View GitHub Profile
@clinuxrulz
clinuxrulz / IncArrow.java
Last active August 29, 2015 14:24
Incremental Arrow Transformer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package clinuxrulz.gmail.rxtest;
import clinuxrulz.gmail.rxtest.inc_arrow.IncArrowArrow;
import clinuxrulz.gmail.rxtest.inc_arrow.IncArrowStatefulArrowTransformer;
import clinuxrulz.gmail.rxtest.inc_arrow.IncArrowCategory;
resume <- callCC (\bail -> do
let suspend = callCC (\k -> bail $ k unit)
suspend
return (return unit)
)
resume
newtype SuspContT r m a = SuspContT ((a -> m (Either (Unit -> SuspContT r m a) r)) -> m (Either (Unit -> SuspContT r m a) r))
runSuspContT :: forall r m a. (MonadRec m) => SuspContT r m a -> (a -> m r) -> m r
runSuspContT s f = tailRecM go s
where
go :: SuspContT r m a -> m (Either (SuspContT r m a) r)
go (SuspContT c) = do
(
either
(\thunk -> Left $ thunk unit)
@clinuxrulz
clinuxrulz / RWSTMonadRec.java
Created April 17, 2016 03:20
RWST MonadRec
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.sm.fp.data.trans.rws;
import com.sm.fp.data.trans.RWST;
import com.sm.fp.kinds.T_;
import com.sm.fp.kinds.T__;
@clinuxrulz
clinuxrulz / ExistsSStreamF.java
Last active May 8, 2016 11:14
Derive4J Stream experiment
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gmail.clinuxrulz.derive4j.test.stream;
/**
*
* @author clintonselke
package com.sm.fp.data.trans;
import com.sm.fp.data.trans.generator.*;
import com.sm.fp.kinds.__;
import com.sm.fp.kinds.__3;
import com.sm.fp.typeclass1.monad.Identity;
import com.sm.fp.typeclass1.monad.Monad;
import com.sm.fp.typeclass1.monad.MonadRec;
import fj.*;
import fj.data.Either;
@clinuxrulz
clinuxrulz / Coerce.java
Last active May 20, 2016 00:04
Leibnizian equality
package com.sm.fp.data.eq.type;
import com.sm.fp.kinds.__;
class Coerce<A> implements __<Coerce.Mu,A> {
public static class Mu {}
private final A value;
private Coerce(A value) {
@clinuxrulz
clinuxrulz / Free.hs
Created July 10, 2016 03:28
F-coalgebra based version.
{-# LANGUAGE RankNTypes, KindSignatures, MultiParamTypeClasses, FlexibleContexts #-}
newtype Free f a = Free (forall m. (Monad m) => f m -> m a)
runFree :: (Monad m) => forall f a. Free f a -> f m -> m a
runFree (Free k) = k
instance Functor (Free f) where
fmap f (Free k) = Free (\impl -> fmap f (k impl))
@clinuxrulz
clinuxrulz / ExampleGuiDSL.java
Created July 20, 2016 10:18
Invariant Functor Use Case
@SuppressWarnings("RedundantTypeArguments")
public static final GuiDSL<GableSoffitParams> gui = GuiDSL.p5(
GuiDSL.<Double, Double, Double, Double, Double>p5(
GuiDSL.labeled("length", GuiDSL.double_()),
GuiDSL.labeled("span", GuiDSL.double_()),
GuiDSL.labeled("height", GuiDSL.double_()),
GuiDSL.labeled("pitch", GuiDSL.double_()),
GuiDSL.labeled("side1Overhang", GuiDSL.double_())
),
GuiDSL.<Double, Double, Double, Double, Double>p5(
@clinuxrulz
clinuxrulz / CoproductTypeable.java
Created July 21, 2016 23:24
Reference implementation for typeable
package com.sm.fp.data.typeable;
import com.sm.fp.DataSinkEffects2;
import com.sm.fp.DataSourceEffects2;
import com.sm.fp.LoadSave3;
import com.sm.fp.data.eq.type.Leibniz;
import com.sm.fp.kinds.__;
import fj.*;
import fj.data.Either;
import fj.data.List;