Skip to content

Instantly share code, notes, and snippets.

@LeifW
LeifW / for.scala
Last active August 23, 2018 19:16
Scala do-notation overloading
case class Foo(a: Int) {
def map(f : Int => Int) = Foo(f(a))
def flatMap(f : Int => Bar): Bar = f(a)
}
case class Bar(a: Int) {
def map(f : Int => Int) = Bar(f(a))
def flatMap(f : Int => Bar): Bar = f(a)
}
@LeifW
LeifW / doInt.idr
Created August 23, 2018 03:21
Do-notation desugaring in Idris
-- Apply the callback that is the rest of the lines of code
(>>=) : Int -> (Int -> Int) -> Int
(>>=) x f = f x
i : Int
i = do
x <- 1
y <- 2
x + y
@LeifW
LeifW / Main.hs
Created July 23, 2018 05:43
running a cabal test
module Main(main, a) where
a = "foo"
main = putStrLn a
@LeifW
LeifW / aeson_dsl.hs
Created July 12, 2018 18:14
Aeson ambiguous instance
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson
thing = object [ "foo" .= "bar" ]
module Main where
import System.Taffybar
import System.Taffybar.Information.CPU
import System.Taffybar.Information.Memory
import System.Taffybar.SimpleConfig
import System.Taffybar.Widget
import System.Taffybar.Widget.Workspaces
import System.Taffybar.Widget.Battery
import System.Taffybar.Widget.SNITray
@LeifW
LeifW / Foo.hs
Created June 13, 2018 07:05
Depends on data-has
{-# LANGUAGE FlexibleContexts, FlexibleInstances, UndecidableInstances #-}
import Data.Has
data Foo = Foo deriving Show
data Bar = Bar deriving Show
class HasFoo r where
foo :: r -> Foo
instance HasFoo Foo where
foo = id
@LeifW
LeifW / epolltest.c
Created May 30, 2018 04:28
Listen to changes in brightness using epoll.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <sys/types.h>
int main(int argc, char** argv) {
@LeifW
LeifW / fp_topics.md
Last active May 29, 2018 04:51
FP topics

Beginning

  • Function definition, application.
  • Pattern matching
  • Recursion
  • map, fold
  • Functions as values

Intermediate

  • data declarations
  • Parametric polymorphism
@LeifW
LeifW / NT.hs
Last active April 14, 2018 08:28
Natural transformation typeclass
{-# LANGUAGE MultiParamTypeClasses, TypeOperators #-}
import Data.Maybe (maybeToList)
class (~>) m n where
nt :: m x -> n x
instance (~>) Maybe [] where
nt = maybeToList
@LeifW
LeifW / PKGBUILD
Created January 24, 2018 06:19
Arch Linux package script for Haskell's hint library
# $Id$
# Maintainer: Daniel Martí <[email protected]>
_hkgname=hint
pkgname=haskell-hint
pkgver=0.7.0
pkgrel=1
pkgdesc="Runtime Haskell interpreter (GHC API wrapper)"
url="https://github.com/mvdan/$_hkgname"
license=('BSD')