Skip to content

Instantly share code, notes, and snippets.

Daniel P. Brice friedbrice

Block or report user

Report or block friedbrice

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@friedbrice
friedbrice / crib-sheet.hs
Created Dec 5, 2019
Haskell Prelude Crib Sheet
View crib-sheet.hs
-----------
-- Types --
-----------
----
-- Builtin Types
----
-- Functions from `a` to `b`.
data a -> b
View pronounce.hs
{-# LANGUAGE FlexibleInstances, OverloadedStrings #-}
import Data.Function ((&))
import Data.String (IsString)
data X
data Y
data Z
data M a
View flipCell.elm
-- updates a board so that a particular cell's status is flipped
flipCell : Cell -> Board -> Board
flipCell c0 b c =
if c == c0
then flipStatus (b c)
else b c
View CoolWay.hs
{-# LANGUAGE DerivingVia #-}
module CoolWay where
import Control.Monad
newtype MonadInstances m a = MonadInstances (m a)
deriving Monad via m
instance Monad m => Functor (MonadInstances m) where
@friedbrice
friedbrice / kwargs.hs
Last active Sep 2, 2019
Haskell Kwargs Dream Syntax
View kwargs.hs
-- dream syntax for Haskell kwargs
mkString :: Show a =>
{ pfx :: String, ifx :: String, sfx :: String } -> [a] -> String
mkString { pfx, ifx, sfx } xs =
pfx ++ infixed xs ++ sfx
where
infixed [] = ""
infixed [x] = show x
infixed (x:xs) = prepend x (infixed xs)
@friedbrice
friedbrice / Maps.java
Last active Aug 14, 2019
A specification for maps (the abstract data type) as a free category. And a short demo of property testing. (JSVerify source available at https://github.com/jsverify/jsverify)
View Maps.java
package local.maps;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.scalacheck.Arbitrary;
import org.scalacheck.Gen;
import org.scalacheck.Prop;
@friedbrice
friedbrice / List.hs
Last active Jul 6, 2019
A functor whose type parameter is nominal.
View List.hs
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RoleAnnotations #-}
module List (List, fromText, list, unList) where
import qualified Data.Text as T
type role List nominal
@friedbrice
friedbrice / MakeImpure.hs
Last active Jun 30, 2019
the name is kind of a joke
View MakeImpure.hs
{-# LANGUAGE
FlexibleInstances,
MultiParamTypeClasses,
FunctionalDependencies,
UndecidableInstances
#-}
module MakeImpure where
data Key a
class Get a where get :: Key a -> IO a
@friedbrice
friedbrice / App.hs
Last active Jun 28, 2019
tidy-records
View App.hs
module App where
import Labels ()
import Types
import Data.Generics.Product.Fields
main :: IO ()
main = do
let
@friedbrice
friedbrice / Extend.java
Last active Jun 4, 2019 — forked from fiddlerwoaroof/extend.js
Static typable EP solution
View Extend.java
import java.util.Map;
// This is almost a solution to the expression problem, except for
// lines 47 and 74.
// Instead of raising an exception, we want the program to fail to
// compile if there are cases that we haven't considered.
class Extend {
// I can define a data structure by cases.
You can’t perform that action at this time.