Skip to content

Instantly share code, notes, and snippets.

View morteako's full-sized avatar

Morten Kolstad morteako

  • Oslo
View GitHub Profile
@morteako
morteako / Proof.hs
Created April 4, 2023 15:17
Fold duality theorems proved in Liquid Haskell - (from An introduction to functional programming Richard Bird, Philip Wadler)
{-@ LIQUID "--reflection" @-}
{-@ LIQUID "--ple" @-}
import Language.Haskell.Liquid.ProofCombinators
import Prelude hiding (flip, foldl, foldr, reverse, (++))
{-@ reflect foldr @-}
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f a [] = a
-- {-@ LIQUID "--reflection" @-}
{-@ LIQUID "--ple" @-}
import qualified Data.Set as Set
import Data.Set (Set)
-- makeLeafSet = Set.fromList . map (uncurry Leaf)
data Bit = B0 | B1 deriving (Eq,Ord)
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS -fwarn-incomplete-patterns #-}
import Prelude hiding (Bool(..))
aa :: a -> a
aa a = a
aba :: a -> b -> a
@morteako
morteako / AllMerges.hs
Created October 29, 2019 23:58
Simple way to get all possible merges of two lists in Haskell
allMerges :: [a] -> [a] -> [[a]]
allMerges [] ys = [ys]
allMerges xs [] = [xs]
allMerges left@(x:xs) right@(y:ys) =
map (x:) (allMerges xs right) ++ map (y:) (allMerges left ys)
-- > f [1,2,3] [11,12,13]
-- [ [1,2,3,11,12,13],
-- [1,2,11,3,12,13],
Haskell:
https://www.codewars.com/kata/5512ec4bbe2074421d00028c
https://www.codewars.com/kata/547202bdf7587835d9000c46
https://www.codewars.com/kata/543d218022e0f307fb000173
noen litt mindre hasklete som kanskje er
fine i Haskell
function compare() {
baseurl="https://github.com/"
remote=$(git remote get-url origin)
tempRepo=${${remote}#"git@github.com:"}
repo=${${tempRepo}%".git"}
branchname=$(git rev-parse --abbrev-ref HEAD)
url=$baseurl$repo"/compare/"$branchname
eval "open -a 'Google Chrome' $url"
}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson.QQ
import Data.Aeson
import Data.Aeson.Lens
import Control.Lens
obj = [aesonQQ|
{
@morteako
morteako / state.scm
Last active September 3, 2019 23:32
;;state :: s -> (a s)
(define (map-state f st)
(lambda (x)
(let* ((res (st x))
(a (car res))
(s (cadr res)))
(state (f a) s))))
import Control.Monad ((<=<))
import Data.Maybe (catMaybes, listToMaybe)
import Safe
xss = [
[1,2,3],
[4,5,6],
[7,8,9]
]
{-# LANGUAGE RebindableSyntax #-}
import Prelude hiding ( (>>=),(>>) )
import qualified Prelude as P
import Liquid.Haskell.ProofCombinators
{-@ (>>) :: x:a -> y:{a | y == x} -> {v:a | v == x && v == y} @-}
(>>) x y = x === y