Skip to content

Instantly share code, notes, and snippets.

View smunix's full-sized avatar

Providence Salumu smunix

View GitHub Profile
@gelisam
gelisam / FixCoRec.hs
Created January 6, 2022 05:19
Defining a recursive datatype by its differences with another recursive datatype
-- | In response to https://twitter.com/_gilmi/status/1478846678409035779
--
-- The challenge is three-fold:
--
-- 1. define the type 'Expr2' as "the same as 'Expr1' but with this constructor
-- instead of that one", without having to repeat all the other constructors.
-- 2. convert from 'Expr1' to 'Expr2' by only providing a translation for the
-- one constructor which is different.
-- 3. write a polymorphic function which works with both 'Expr1' and 'Expr2'
-- because it doesn't touch the constructor which differs.
@jmatsushita
jmatsushita / README
Last active May 13, 2024 18:21
Setup nix, nix-darwin and home-manager from scratch on an M1 Macbook Pro
###
### [2023-06-19] UPDATE: Just tried to use my instructions again on a fresh install and it failed in a number of places.
###. Not sure if I'll update this gist (though I realise it seems to still have some traffic), but here's a list of
###. things to watch out for:
### - Check out the `nix-darwin` instructions, as they have changed.
### - There's a home manager gotcha https://github.com/nix-community/home-manager/issues/4026
###
# I found some good resources but they seem to do a bit too much (maybe from a time when there were more bugs).
# So here's a minimal Gist which worked for me as an install on a new M1 Pro.
{-# LANGUAGE RankNTypes #-}
import Control.Comonad.Cofree
import Control.Lens hiding ((:<))
import qualified Data.Map as Map
import Data.Map (Map)
import Prelude hiding (lookup)
import Data.Maybe (isJust)
import Test.QuickCheck
@smunix
smunix / fldr.hs
Last active April 9, 2021 10:24
Playing with endomorphisms and monoids
newtype Fn a = Fn {unFn :: a -> a}
instance Semigroup (Fn a) where
(<>) (Fn a) (Fn b) = Fn (b . a)
import Control.Monad
import Data.Foldable (fold)
import Data.Monoid (appEndo)
import Hedgehog
image: nixpkgs/cachix-flakes:nixos-20.03
build:
before_script:
- mkdir -p /etc/nix
- echo "experimental-features = nix-command flakes ca-references recursive-nix" >> /etc/nix/nix.conf
- cachix use numtide
- nix path-info --all > /tmp/store-path-pre-build
script:
- nix flake check

With scoped effects, handlers must be a part of the program

It is seductive to imagine that effect handlers in an algebraic effect system are not part of the program itself but metalanguage-level folds over the program tree. And in traditional free-like formulations, this is in fact the case. The Eff monad represents the program tree, which has only two cases:

data Eff effs a where
  Pure :: a -> Eff effs a
  Op :: Op effs a -> (a -> Eff effs b) -> Eff effs b

data Op effs a where
@abhin4v
abhin4v / dfs.hs
Last active December 22, 2020 12:16
Implementation of depth first search in Haskell
module DepthFirstSearch where
import Data.Foldable (asum)
import Data.List ((\\))
dfs :: (Eq a) => (a -> [a]) -> a -> a -> Maybe [a]
dfs next start goal = dfs' [] start
where dfs' path current
| current == goal = Just . reverse $ goal : path
| null nexts = Nothing
@smunix
smunix / typing.md
Created October 18, 2015 16:41 — forked from chrisdone/typing.md
Typing Haskell in Haskell

Typing Haskell in Haskell

MARK P. JONES

Pacific Software Research Center

Department of Computer Science and Engineering

Oregon Graduate Institute of Science and Technology

@chrisdone
chrisdone / typing.md
Last active May 9, 2024 15:27
Typing Haskell in Haskell

Typing Haskell in Haskell

MARK P. JONES

Pacific Software Research Center

Department of Computer Science and Engineering

Oregon Graduate Institute of Science and Technology