Skip to content

Instantly share code, notes, and snippets.

View rampion's full-sized avatar

Noah Luck Easterly rampion

  • Mercury Technologies
View GitHub Profile
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
@rampion
rampion / ZipWith.hs
Last active July 8, 2021 03:52
Two implementations of a variadic `zipWith` function, based on inferring the type using either the argument or the return type
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module ZipWith where
import Control.Applicative (ZipList (..))
import Prelude hiding (zipWith)
@rampion
rampion / Lib.hs
Last active May 24, 2021 00:55
ShortestLongest
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall -Wextra -Werror -Wno-name-shadowing -Wno-unused-top-binds #-}
module Lib
( shortestLongest,
)
where
@rampion
rampion / HyperList.hs
Last active February 22, 2023 11:21
Demonstration of how the Hyperfunction implementation of list works.
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall -Werror -Wextra -Wno-name-shadowing #-}
module HyperList where
import Data.Function ((&))
newtype a -&> b = Hyp {invoke :: (b -&> a) -> b}
@rampion
rampion / HyperPhases.hs
Created May 16, 2021 08:04
Breadth-first traversal of a rose tree using a Scott encoding of the Phases applicative
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE Rank2Types #-}
{-# OPTIONS_GHC -Wall -Werror -Wextra -Wno-name-shadowing #-}
module HyperPhases where
import Control.Applicative (liftA2)
import Data.Functor ((<&>))
newtype Phases f a = Phases
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall -Werror -Wextra #-}
module Hyperfunction where
import Control.Category
import Data.Function (fix)
import Prelude hiding (id, (.))
extern crate structopt;
use clap::ArgGroup;
use structopt::StructOpt;
#[derive(Debug, StructOpt, PartialEq)]
#[structopt(group(ArgGroup::with_name("confs").multiple(true)))]
pub struct Command {
#[structopt(long = "config", group = "confs", parse(from_str = config))]
configs: Vec<Conf>,
@rampion
rampion / monad.rs
Created December 8, 2020 19:23
An implementation of the Functor/Applicative/Monad trait family using carrier types.
#![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 December 5, 2020 16:15
"Implement the reverse function using the sort function" from https://bindthegap.news/issues/BindTheGap-01Nov2020.pdf
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module SortAsReverse where
-- challenge from bindthegap.news issue 1, Nov 2020
--
-- implement reverse using sort
import Data.Coerce (coerce)
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}