Skip to content

Instantly share code, notes, and snippets.

View owickstrom's full-sized avatar

Oskar Wickström owickstrom

View GitHub Profile
owickstrom / Main.purs
Last active December 8, 2016 20:07
PureScript record and mutual recursion problem with Instances
View Main.purs
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
type R m = { f ∷ Int → m Int }
makeDecr ∷ ∀ m. Monad m ⇒ R m → R m
makeDecr r = { f: \n → if n > 0 then r.f (n - 1) else pure n }
owickstrom / compile-error.txt
Created December 8, 2016 19:17
View compile-error.txt
No type class instance was found for
Control.Monad.Monad m0
while checking that expression { path: [ "contact"
, GET: handler (\conn ->
owickstrom /
Last active November 28, 2016 17:16
Composing Alt Functions

What I want is to "compose" functions taking some argument and returning an Alt value, like a -> m b where Alt b. The resulting value should be a function from a -> m b. The implementation below does that, but I was wondering if there's a better way? I'm thinking that maybe I could create a newtype wrapper around these functions, and an Alt instance for that type, but I haven't gotten that to work, and I'm not sure it's a good approach.

owickstrom / SafeWeb.purs
Last active November 13, 2016 14:46
Safe web routes in PureScript
View SafeWeb.purs
module SafeWeb where
import Prelude
import Data.Array (filter)
import Data.Leibniz (type (~))
import Data.String (Pattern(Pattern), split, joinWith)
type Path = Array String
pathToHtml :: Path -> String
owickstrom / TypeSynonymsProblem.purs
Created October 29, 2016 12:26
PureScript type synonym problem with effect kind
View TypeSynonymsProblem.purs
module TypeSynonymsProblem where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Either (Either)
import Data.Tuple (Tuple(Tuple))
type Foo e a a' b b' = Eff e (Tuple a b) -> Eff e (Tuple a' b')
type Bar e a a' b b' = Eff e (Either a b) -> Eff e (Either a' b')
owickstrom / Name.idr
Created October 13, 2016 05:52
Idris String with validation?
View Name.idr
-- A data type wrapping a non-empty string
data Name : Type where
MkName : (s : String) -> (not (s == "") = True) -> Name
-- Some function that expects a valid Name
test : Name -> String
test (MkName s _) = s
-- Usage of that function. Do I need Refl here? Any better way of doing this?
foo : String
owickstrom / protocols.go
Last active April 11, 2016 12:06
Protocols sketches for Oden
View protocols.go
// Types that support addition and multiplication.
protocol Semiring(a) {
add : a -> a -> a
zero : a
mul : a -> a -> a
one : a
owickstrom / based-on-existing-syntax.lisp
Last active January 22, 2016 08:52
Alternate syntax
View based-on-existing-syntax.lisp
(pkg main)
(import fmt)
;; if expressions
(: fib (int -> int))
(def (fib n)
(if (== n 1)
(if (== n 2)
owickstrom /
Last active October 27, 2015 08:46
Kashmir Programming Language - Draft
owickstrom / type-system.rkt
Created October 12, 2015 06:14
Minimalistic type system hack in Racket.
View type-system.rkt
#lang racket
(require "minikanren/mk.rkt")
(struct e/var (name) #:transparent)
(struct e/app (fn param) #:transparent)
(struct e/lam (arg body) #:transparent)
(define (t/fn domain range)
(list ':fn domain range))