Skip to content

Instantly share code, notes, and snippets.

@duplode
duplode / phantom.md
Last active January 29, 2022 16:44
A proof of phantom = fmap f

A proof of phantom = fmap f

phantom is defined as:

phantom :: (Functor f, Contravariant f) => f a -> f b
phantom = contramap (const ()) . fmap (const ())

By parametricity on phantom, we have:

fmap k . phantom = phantom . fmap h

{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
-- Inspired by:
-- https://github.com/fumieval/data-functor-logistic
-- https://gist.github.com/viercc/2e6c1d8566a6fbaf0d21c09103e60b76
module Iteration where
@duplode
duplode / Whereslift.hs
Last active June 23, 2019 22:55
"Where's lift?" -- Runnable examples from https://stackoverflow.com/a/56726855/2751851
#!/usr/bin/env cabal
{- cabal:
build-depends: base >= 4.12
, mtl
, distributive
-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
@duplode
duplode / ListBox.hs
Last active December 23, 2015 05:59
An experimental list box widget for Threepenny 0.3 (https://github.com/HeinrichApfelmus/threepenny-gui).
{-# LANGUAGE RecordWildCards #-}
module ListBox
( ListBox
-- Construction
, new
-- Model definition and setup
, plugModel
-- Default renderer
, toElement
-- Appearance modifiers
@duplode
duplode / InputElement.hs
Last active December 22, 2015 17:29 — forked from HeinrichApfelmus/InputElement.hs
(Obsolete) variation of Apfelmus' example of a widget following the principles proposed in http://apfelmus.nfshost.com/blog/2012/03/29-frp-three-principles-bidirectional-gui.html .
{-# LANGUAGE RecordWildCards #-}
module InputElement where
import Data.Monoid
import Control.Monad
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny
@duplode
duplode / Counter.hs
Last active December 21, 2015 13:59
A simple proof of concept of reusable components for reactive-banana-threepenny.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RecordWildCards #-}
-- Import this module qualified.
module Counter
( Counter
-- Constructor
, new
-- Element renderer
, toElement
-- Setter-like