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 / 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.
@friedbrice
friedbrice / Sets.hs
Last active Jun 3, 2019
Some objecty sets in Haskell
View Sets.hs
module OOP where
import Data.Text (Text)
data Set a = Set {
isEmpty :: Maybe Bool,
contains :: a -> Bool,
intersection :: Set a -> Set a,
union :: Set a -> Set a
}
@friedbrice
friedbrice / lenses-introduction.js
Last active Jun 9, 2019
Javascript has lenses?
View lenses-introduction.js
var danielsLensTalk = {
recordId: 0,
creation: {
user: 'danielbrice@gmail.com',
moment: {
date: {
year: 2019,
month: 5,
day: 29
},
View BooleanAlgebra.hs
{-# LANGUAGE DerivingVia, TypeApplications #-}
import Prelude hiding ((&&), (||), not)
import qualified Prelude ((&&), (||), not)
class BooleanAlgebra a where
(&&) :: a -> a -> a
(||) :: a -> a -> a
not :: a -> a
true :: a
false :: a
@friedbrice
friedbrice / App.hs
Last active May 7, 2019
"Mmm, Cake" or "A Method of Application Wiring for Large-Scale Haskell Programs"
View App.hs
module App where
-- Write the parts of your program that do IO in MTL style,
-- but don't use the `MonadIO` class. -_-
-- This is Layer 2. Layer 3 (not shown) is business logic.
class Foo m where
foo :: String -> m ()
class Bar m where
@friedbrice
friedbrice / LoggingExample.hs
Last active May 31, 2019
Decorating pure functions with effects
View LoggingExample.hs
module LoggingExample where
import System.Environment (getArgs)
data MyFoo
instance Read MyFoo
instance Show MyFoo
data MyBar
instance Show MyBar
@friedbrice
friedbrice / TheRightWay.hs
Last active Apr 24, 2019
How (and how not) to make testable code in Haskell
View TheRightWay.hs
module TheRightWay where
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Maybe
myProgram :: Monad m => m String -> (String -> m Int) -> Int -> m String
myProgram readLine parseInt n = do
line <- readLine
You can’t perform that action at this time.