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
@friedbrice
friedbrice / monadstate-example.hs
Last active April 4, 2024 16:57
MonadState Example
-- monadstate-example.hs
--
-- Load this program in GHCi:
--
-- stack repl \
-- --resolver nightly \
-- --package transformers \
-- --package mtl \
-- monadstate-example.hs
--
@friedbrice
friedbrice / haskell-time.hs
Last active April 4, 2024 16:09
Haskell Time Crib Sheet
-- ghcid -c'stack repl --resolver nightly --package time' haskell-time.hs --allow-eval
----
-- # Haskell Time Crib Sheet
----
-- Excellent sources for this small guide include:
--
-- * https://two-wrongs.com/haskell-time-library-tutorial.html
-- * https://williamyaoh.com/posts/2019-09-16-time-cheatsheet.html
@friedbrice
friedbrice / lenses-introduction.js
Last active April 4, 2024 16:02
Javascript has lenses?
var danielsLensTalk = {
recordId: 0,
creation: {
user: 'danielbrice@gmail.com',
moment: {
date: {
year: 2019,
month: 5,
day: 29
},
-- Inspired by http://www.csis.pace.edu/~bergin/patterns/ppoop.html
-- and by Rob Pike's response: https://plus.google.com/+RobPikeTheHuman/posts/hoJdanihKwb
import System.Info (os)
import Data.Map (Map, findWithDefault, fromList)
class AbstractOsObject a where
getOsString :: a -> String
coerce :: a -> BaseOsObject
@friedbrice
friedbrice / BeginnerArgs.hs
Last active July 28, 2023 10:26
Haskell Command-line Arguments (scroll down for prose).
import System.Environment (getArgs)
myApp :: [String] -> IO ()
myApp args =
case args of
[name] -> putStrLn ("Top of the morning to you, " ++ name)
_ -> putStrLn "I only know how to use one argument D:"
main :: IO ()
main = do
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# OPTIONS_GHC -Wall #-}
module FileSystem where
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Bifunctor
{-# OPTIONS_GHC -Wall -fno-warn-orphans -fno-warn-unused-top-binds -fno-warn-name-shadowing #-}
{-# LANGUAGE FunctionalDependencies, OverloadedStrings #-}
import Data.List hiding (singleton)
import Data.Map
import Data.Semigroup
import Data.String
import GHC.Num.Integer qualified
import GHC.Real qualified
import Numeric.Natural
@friedbrice
friedbrice / Escardo.hs
Last active October 21, 2022 02:24
Looking for a Needle That Might Not Be in an Infinite Haystack
-- Based on "Infinite sets that admit fast exhaustive search" by Martín Escardó
--
--
--
--
--
--
--
--
--
@friedbrice
friedbrice / main.hs
Created July 18, 2022 17:40 — forked from itsuart/main.hs
Hello world Yesod example.
{-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings #-}
import Yesod
import Yesod.Core.Handler
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [parseRoutes|
/ HomeR GET
|]
@friedbrice
friedbrice / App.hs
Last active May 13, 2022 05:29
Zero-parameter type classes as a dependency injection framework. (Don't ever do this in real life.)
module Yolo.App where
import Yolo.Capabilities
app :: (Console, Database, Exception, Logging) => IO ()
app = do
x1 <- loggingDivision 6 2
x2 <- loggingDivision 5 0
x3 <- consoleDivision