using System;
namespace Free3
{
public static partial class ƒ
{
#region Syntactic Sugar
public static Coyoneda<V, B, B> ToCoyo<V, B>(this V value) => new Coyoneda<V, B, B>(value, z => z);
#endregion
public static R Lower<V, R>(this Coyoneda<V, V, R> @this) => @this.f(@this.value);
}
public class Coyoneda<V, A, B> : IFunctor<B>
{
public IFunctor<C1> Map<C1>(Func<B, C1> map) => new Coyoneda<V, A, C1>(value, z => map(f(z)));
public readonly V value;
public readonly Func<A, B> f;
public Coyoneda(V value, Func<A, B> f)
{
this.value = value;
this.f = f;
}
}
public interface IFunctor<T>
{
IFunctor<T1> Map<T1>(Func<T, T1> map);
}
public interface IFoldable<T>
{
T Fold(Alg<T> alg);
}
public interface IMonad<T>
{
IMonad<T1> Bind<T1>(Func<T, IMonad<T1>> bind);
}
public class Id<T> : IFunctor<T>, IMonad<T>
{
private T source;
public Id(T v) => source = v;
public IFunctor<T1> Map<T1>(Func<T, T1> map) => new Id<T1>(map(source));
public IMonad<T1> Bind<T1>(Func<T, IMonad<T1>> bind) => bind(source);
}
public abstract class Alg<T>
{
public abstract T Pure(Pure<T> val);
}
public class G
{
public G()
{
}
}
public abstract class Free<T>
{
public abstract Free<T1> Map<T1>(Func<T, T1> map);
public abstract Free<T1> Bind<T1>(Func<T, Free<T1>> bind);
public abstract IMonad<T> FoldMap(Func<T, IMonad<T>> Typerep);
}
public interface AbstractInterpreter<F>
{
void Eval(Interpretable<F> a);
}
public class Pure<T> : Free<T>
{
public T source;
public Pure(T v) => source = v;
public override Free<T1> Map<T1>(Func<T, T1> map) => new Pure<T1>(map(source));
public override Free<T1> Bind<T1>(Func<T,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.