Skip to content

Instantly share code, notes, and snippets.

View friedbrice's full-sized avatar
🔵
You have unread notifications

Daniel P. Brice friedbrice

🔵
You have unread notifications
View GitHub Profile
@StevenClontz
StevenClontz / generate.rb
Created March 11, 2015 04:58
progress report generator
require 'csv'
require 'pry'
require 'erb'
class Student
attr_reader :id, :name, :section
attr_accessor :group1,
:group2,
:absences,
:diagnostic,
data Lit = Lit Int
data Add l r = Add l r
class Eval x where
eval :: x -> Int
instance Eval Lit where
eval (Lit x) = x
instance (Eval l, Eval r) => Eval (Add l r) where
@i-am-tom
i-am-tom / Record.hs
Last active April 2, 2019 08:46
A tutorial in record manipulation.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@eborden
eborden / stack-ghcid.sh
Last active May 16, 2019 14:43
Run ghcid in a monorepo via stack
project=$(basename "$(pwd)")
# build dependencies
build_deps="stack build $project --fast --pedantic --dependencies-only --interleaved-output"
# restart on changes in other packages
restarts=$(find ../. -maxdepth 1 -type d \
-not -name "$project" \
-not -name .stack-work \
-not -name . \
{-# LANGUAGE TemplateHaskell, RankNTypes #-}
module DbCodeGen where
import Data.List (intercalate)
import Control.Lens
type Endo a = a -> a
fix :: Endo a -> a
fix f = f (fix f)
@fiddlerwoaroof
fiddlerwoaroof / extend.js
Last active June 13, 2019 17:32
Static typable EP solution
//
// Two kinds of animals: dogs and cats
//
// I want greet and leave to be defined such that there are four
// different behaviors corresponding to each combination of dog and
// cat
//
class Animal {
receive_operation(operation) {
console.log("the animal is unresponsive");
@jessitron
jessitron / haskellyte.md
Created August 1, 2014 16:12
Gershom's Letter to a Young Haskell Enthusiast, condensed. I removed a lot of words, kept the themes, moved a few around a bit.

Letter to a Young Haskell Enthusiast, by Gershom Bazerman.

Condensed from: http://comonad.com/reader/2014/letter-to-a-young-haskell-enthusiast/

The following letter is about tendencies that come with the flush of excitement of learning any new thing. It is written specifically, because if we don't talk specifics, the generalities make no sense. It is a letter full of things I want to remember.

You’ve entered the world of strongly typed functional programming, and it is great. You want to share the great things you’ve learned, and you want to slay all the false statements in the world.

{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
@gelisam
gelisam / StringPattern.hs
Created January 30, 2020 14:39
A Haskell reimplementation of Scala's "direct pattern-matching on strings"
-- in response to https://twitter.com/chrislpenner/status/1221784005156036608
--
-- The goal is to mimic this Scala code, but in Haskell:
--
-- > "spotify:user:123:playlist:456" match {
-- > case s"spotify:user:$userId:playlist:$playlistId"
-- > => ($userId, $playlistId) // ("123", "456")
-- > }
{-# LANGUAGE DeriveFunctor, LambdaCase, PatternSynonyms, QuasiQuotes, RankNTypes, TemplateHaskell, TypeOperators, ViewPatterns #-}
{-# OPTIONS -Wno-name-shadowing #-}
@ObjectBoxPC
ObjectBoxPC / pangram.hs
Last active July 7, 2020 13:48
Simple Haskell program to check if the input (command-line arguments) form a pangram, containing all 26 letters of the English alphabet
import Data.Char (toUpper)
import Data.List (intercalate)
import Data.List.NonEmpty (NonEmpty, nonEmpty, toList)
import System.Environment (getArgs)
data PangramResult = Pangram | MissingLetters (NonEmpty Char)
checkPangram :: String -> PangramResult
checkPangram s = case nonEmpty missingLetters of
Just ls -> MissingLetters ls