Skip to content

Instantly share code, notes, and snippets.

@rampion
rampion / HyperList.hs
Last active April 6, 2024 19:16
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
@DarinM223
DarinM223 / tooling.md
Last active January 26, 2021 03:33
Haskell/Purescript/Lisp tooling

Haskell

Package manager

The main package manager to use in Haskell is Cabal. Make sure that the Cabal version that you are using is at least 3.0. Then build, repl, install, etc will use the upgraded v2-style versions that work with minimal problems.

Documentation

@roman
roman / mvar.rs
Created August 18, 2019 21:46
Fun exercise of implementing Haskell's MVar in Rust
use std::sync::{Condvar, Mutex};
pub struct MVar<T> {
locked_value: Mutex<Option<T>>,
empty_cond: Condvar,
full_cond: Condvar,
}
// Methods of MVar that need the Clone type constraint
impl<T> MVar<T>
@sjoerdvisscher
sjoerdvisscher / equipment.hs
Last active May 23, 2020 14:51
Proarrow equipment in Hask
{-# LANGUAGE
GADTs
, DataKinds
, PolyKinds
, RankNTypes
, TypeOperators
, KindSignatures
, TypeApplications
, FlexibleContexts
, FlexibleInstances
@i-am-tom
i-am-tom / FizzBuzz.hs
Last active June 26, 2023 16:35
Arguably the fastest implementation of FizzBuzz ever written.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnsaturatedTypeFamilies #-}
import GHC.TypeLits
import Prelude hiding (Functor, Semigroup)
type Main = (Fizz <> Buzz) <$> (0 `To` 100)
#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages(p: with p; [type-level-sets])"
#! nix-shell -I nixpkgs=channel:nixos-18.03
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}

Nix Flake MVP

Goals

  • To provide Nix repositories with an easy and standard way to reference other Nix repositories.

  • To allow such references to be queried and updated automatically.

  • To provide a replacement for nix-channel, NIX_PATH and Hydra

@DarinM223
DarinM223 / typeclassses.md
Last active March 31, 2023 03:35
Typeclasses in Haskell, Scala, and Rust

Type classes

Type classes have some advantages over Java style interfaces. One advantage is the ability to implement functions that do not need to take in an instance of the interface.

For example, (FromString v) takes in a String and returns v, and it doesn't have to take v as a parameter.

Copyright 2017 Austin Seipp
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.