Skip to content

Instantly share code, notes, and snippets.

View holoed's full-sized avatar
😀

Edmondo Pentangelo holoed

😀
View GitHub Profile
@holoed
holoed / app.py
Created August 9, 2023 14:40
Python Interpreter
from dataclasses import dataclass
from typing import Callable, Generic, TypeVar, Dict
T = TypeVar('T')
V = TypeVar('V')
R = TypeVar('R')
class Reader(Generic[R, T]):
def __init__(self, func: Callable[[R], T]):
self.func = func
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "JuniorLib.h"
#define eqT14 0
#define numT14 1
struct BoxedValue* fac();
@holoed
holoed / main.c
Created October 13, 2021 17:09
Junior Closures Env C Hashtables
#include <string.h> /* strcpy */
#include <stdlib.h> /* malloc */
#include <stdio.h> /* printf */
#include "uthash.h"
struct closure {
void* fn;
struct BoxedValue** env;
};
@holoed
holoed / bubbleSort.hs
Created July 27, 2017 13:23
A duality of sorts
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DeriveFunctor #-}
module Main where
-- Fix point
fix :: ((a -> b) -> (a -> b)) -> (a -> b)
fix f = f (fix f)
@holoed
holoed / LambdaLifting.hs
Last active June 1, 2016 07:41
Lambda Lifting as SLPJ - 1987 Book Page 227
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DeriveFunctor #-}
module LambdaLifting where
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Writer
import Control.Monad.State hiding (fix)
import Data.Char
{-#LANGUAGE DeriveFunctor#-}
module Main where
import Prelude hiding (takeWhile)
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
data Fix f = In { out :: f (Fix f) }
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
data Fix f = In { out :: f (Fix f) }
ana :: Functor f => (a -> f a) -> (a -> Fix f) -> a -> Fix f
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
data Fix f = In { out :: f (Fix f) }
ana :: Functor f => (a -> f a) -> (a -> Fix f) -> a -> Fix f
@holoed
holoed / JsonParser.hs
Last active March 31, 2017 16:01
Json Parser Example
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
newtype Fix f = In { out :: f (Fix f) }
type Algebra f a = f a -> a
@holoed
holoed / ParserAnamorphisms.hs
Created March 27, 2016 20:34
Monadic Parsers as Anamorphisms Co-Algebras
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
newtype Fix f = In { out :: f (Fix f) }
ana :: Functor f => (a -> f a) -> (a -> Fix f) -> a -> Fix f