Skip to content

Instantly share code, notes, and snippets.

@rampion
rampion / monad.rs
Created Dec 8, 2020
An implementation of the Functor/Applicative/Monad trait family using carrier types.
View monad.rs
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
use std::marker::PhantomData;
macro_rules! do_notation {
(| $ty:ty | pure $e:expr) => {
<$ty>::pure($e)
};
(| $ty:ty | $e:expr) => {
$e
@rampion
rampion / SortAsReverse.hs
Created Dec 5, 2020
"Implement the reverse function using the sort function" from https://bindthegap.news/issues/BindTheGap-01Nov2020.pdf
View SortAsReverse.hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module SortAsReverse where
-- challenge from bindthegap.news issue 1, Nov 2020
--
-- implement reverse using sort
import Data.Coerce (coerce)
View BlockMatrix.hs
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
View README.md

WHAT hey

what ho

  1. What's a recipe?
  2. What's a target?
  3. What's a rule?
  4. What's that `.PHONY` thing?
  5. What's that `.DEFAULT_GOAL` thing?
View NamedFunctors.hs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
@rampion
rampion / Money.hs
Last active Jan 16, 2020
Showing how to generalize PMoney and SMoney using dependent types and singletons, follow up to https://twitter.com/alexnixon_uk/status/1217446321348661248?s=20
View Money.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
View README.md

What is the type of \f x -> f (f x)?

View plan.cpp
#include <memory>
#include <iostream>
// TODO compare w/ operator::new
namespace plan {
template <typename A, typename B>
struct Apply {
using Target = typename A::Target;
@rampion
rampion / Tree.hs
Last active Mar 2, 2018
Traversing trees
View Tree.hs
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- | All about traversing 'Tree's
module Tree where
import Control.Applicative (liftA2)