Skip to content

Instantly share code, notes, and snippets.

@LightAndLight
LightAndLight / phil.txt
Created January 9, 2017 23:42
Functional PHP
<?php
/*
Original Code
data List a = Nil | Cons a (List a)
ifte : Bool -> a -> a -> a
ifte cond a b = case cond of { true -> a; false -> b }
class Monad m where {
return : a -> m a;
bind : m a -> (a -> m b) -> m b
}
liftM2 : forall a b c m. Monad m => (a -> b -> c) -> m a -> m b -> m c
liftM2 f ma mb = bind ma (\a. bind mb (\b. return (f a b)))
data Maybe a = Nothing | Just a
@LightAndLight
LightAndLight / monad.php
Last active April 4, 2017 05:26
Monads!? In PHP!?
<?php
class Monad {
public function __construct($return, $bind) {
$this->return = $return;
$this->bind = $bind;
}
}
$liftM2 = function($dict77) {
@LightAndLight
LightAndLight / typeclasses.lam
Created April 8, 2017 14:49
PHP x Functional x Typeclasses
class Functor f where {
fmap : (a -> b) -> f a -> f b
}
class Functor f => Applicative f where {
pure : a -> f a;
ap : f (a -> b) -> f a -> f b
}
class Applicative f => Monad f where {
@LightAndLight
LightAndLight / purescript-2803.md
Last active July 3, 2017 09:17
Bug dissection for #2803

purescript/purescript#2803

By the time it gets to the type checker, the % operator has been desugared to Var (Qualified (Just (ModuleName [ProperName "Main"])) (Ident "f")). The f introduced by the let binding is unqualified (Qualified Nothing (Ident "f")), and it seems that the qualified f is removed from the environment inside the scope of the let. I think that they should both be in scope, since they are different variables- one qualified, and one not.

It doesn't seem to be a general problem with let bindings and qualified names, because this compiles:

@LightAndLight
LightAndLight / BindOf.hs
Last active July 24, 2017 01:19
bindOf
bindOf :: Monad m => Lens s t a b -> m s -> (a -> m b) -> m t
bindOf l ms f = do
s <- ms
b <- f (getConst $ l Const s)
pure $ s & l .~ b
@LightAndLight
LightAndLight / teams.md
Last active August 13, 2017 00:28
Doing engineering right, from Brett Hooker

Creating a work environment where everyone is focused on the invention, engineering and delivery is a delicate and inspiring challenge. There are many people who are focused on agendas outside of the core goal of creating amazing tech. Those distractions are often the death of creativity; yet as they [are] a normal part of working life it becomes one of the greatest challenges for leaders in tech to permit enough diversity in general thought that creativity can still flourish, but to limit it so that it doesn't drown out the core focus of the work.

It's been my experience that you should seek to build teams that share a passion for the project that is so strong that they either park their biases outside, or they are simply so focussed that they don't even think to bring them to the table. Imagine being "in the zone" and wanting nothing other than to build amazing technology and to work with a peer group who only wants to do the same. So much so you no longer notice race, creed,

_1st :: Prism' a a' -> Prism' (a, b, c) (a', b, c)
_1st p = prism' (\(a', b, c) -> (p # a', b, c)) (\(a, b, c) -> (,,) <$> a ^? p <*> pure b <*> pure c)
_2nd :: Prism' b b' -> Prism' (a, b, c) (a, b', c)
_2nd p = prism' (\(a, b', c) -> (a, p # b', c)) (\(a, b, c) -> (,,) a <$> b ^? p <*> pure c)
test :: Prism Integer [Digit]
test = prism' (snd . digitsToInt) intToDigits
where
digitsToInt :: [Digit] -> (Int, Int)
digitsToInt [] = (0, 0)
digitsToInt (d:ds) =
let (count, res) = digitsToInt ds
in (count+1, 10 ^ count * digitToInt d)
intToDigits :: Int -> Maybe [Digit]
with import <nixpkgs> { };
let
latest =
import (fetchTarball https://github.com/nixos/nixpkgs-channels/archive/129f8d7e999b1a1f0fceaecadca30211e34d85a6.tar.gz) {};
in
latest.haskellPackages.callPackage
./hpython.nix
{
inherit (import ./papa.nix latest.haskellPackages);
tasty-hedgehog = import ../tasty-hedgehog { pkgs = latest; };