Skip to content

Instantly share code, notes, and snippets.

module Foo.Bifunctor
(
-- * These
These (..), these'fold, these'fst, these'snd
-- * TupleF
, TupleF (..), tupleF'fst, tupleF'snd
-- * TupleFirstF
, TupleFirstF (..), tupleFirstF'fst, tupleFirstF'snd
@chris-martin
chris-martin / lazy.md
Last active September 16, 2017 20:16

Let's say we want to test whether the list [1,2,3,4,5] contains 2.

We could do this by turning the list of integers [1,2,3,4,5] into a list of Booleans [False, True, False, False, False] indicating, for each element in the original list, whether it is equal to 2.

λ> x = map (== 2) [1..5]
Game update: AppID 289070 "Sid Meier's Civilization VI", ProcID 1869, IP 0.0.0.0:0
ERROR: ld.so: object '/home/chris/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/home/chris/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
/home/chris/.local/share/Steam/steamapps/common/Sid Meier's Civilization VI/./Civ6: /steamrt/amd64/lib/x86_64-linux-gnu/libdbus-1.so.3: no version information available (required by /steamrt/
amd64/lib/libpulse.so.0)
/home/chris/.local/share/Steam/steamapps/common/Sid Meier's Civilization VI/./Civ6: /steamrt/amd64/lib/x86_64-linux-gnu/libdbus-1.so.3: no version information available (required by /nix/stor
e/2d99a5a45cij7nvjxqxxvkiyka7hmh6h-libpulseaudio-10.0/lib/pulseaudio/libpulsecommon-10.0.so)
>>> Adding process 1869 for game ID 289070
GameAction [AppID 289070, ActionID 2] : LaunchApp changed task to
data EqBy a = EqBy (a -> Bool) a
instance Eq (EqBy a) where
EqBy f _ == EqBy _ y = f y
eqBy :: (a -> a -> Bool) -> a -> EqBy a
eqBy f x = EqBy (f x) x
equalBy :: (a -> a -> Bool) -> [a] -> [a] -> Bool
equalBy f xs ys = fmap (eqBy f) xs == fmap (eqBy f) ys

This is an edited excerpt from the transcript of Bartosz Milewski's Category Theory 1.1: Motivation and Philosophy.

Motivation

Turing machine and assembly approaches to programming are not very practical; it's possible, but they don't really scale. So we came out with languages that offer higher levels of abstraction. The next level abstraction was procedural programming. You divide a big problem into procedures, and each procedure has its name, has a certain number of arguments. Maybe it returns a value. Sometimes, not necessarily. Maybe it's just for side effects. You chop up your work into smaller pieces and you can deal with bigger problems.

The next thing people came up with this idea of object-oriented programming right, even more abstract. Now you have stuff that you are hiding inside objects, and then you can compose these objects. Once you program an object, you don't have to look inside the object; you can forget about the implementation and just

@media (min-width: 1100px) {
.drawer {
width: 24%;
}
.column {
width: 24.5%;
}
}
let u2f-rules = let
rev = "e2ce7b157b76bb384f8aba7acbfa73af2dd2fee7";
url = "https://raw.githubusercontent.com/Yubico/libu2f-host/${rev}/70-u2f.rules";
sha256 = "0cydmprvfb442f0hcapd3ac8rb66q0basa89scyzxq1ls61c2cdf";
in pkgs.stdenv.mkDerivation {
src = pkgs.fetchurl { inherit url sha256; };
name = "u2f-rules";
unpackPhase = "true";
installPhase = ''
mkdir -p $out/lib/udev/rules.d
data Person = Person { firstName :: String, lastName :: String, age :: Int }
fullName :: Person -> String
fullName = firstName <> (const " ") <> lastName
summary :: Person -> String
summary = const "Name: " <> fullName <> const "; Age: " <> (show <$> age)
@chris-martin
chris-martin / nixos-from-ubuntu.md
Last active February 17, 2024 18:17
How to install NixOS from an Ubuntu liveCD
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
newtype Reader r a = Reader { runReader :: r -> a }
deriving (Functor, Applicative, Monad)
ask :: Reader a a
ask = Reader id
succ :: Reader Int Int
succ = do