Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE DeriveFunctor, DeriveTraversable, RankNTypes, ScopedTypeVariables #-}
module Example where
import Control.Lens
import Data.Functor.Foldable
data PathComponent d a = Directions d | Alt [a] deriving (Show, Functor, Foldable, Traversable)
traversePC ::
{-# LANGUAGE
DeriveFunctor, DeriveFoldable, DeriveTraversable, TemplateHaskell,
RankNTypes, LambdaCase #-}
import Data.Functor.Foldable
import Data.Functor.Foldable.TH (makeBaseFunctor)
data Tree a = Leaf a | Branch a (Tree a) (Tree a)
makeBaseFunctor ''Tree
@Lysxia
Lysxia / gist:d64bbfc4f7acb25a315f5ca605dd2ddc
Created February 11, 2019 23:03
infinite random list
import Test.QuickCheck
randomList :: Gen [Double]
randomList = do
start <- choose (0.7 :: Double, 1.2)
go start
where go prev = do
new <- choose (min 0.7 (prev-0.1), max (prev+0.1) 1.2)
acc <- go new
return (new : acc)
@Lysxia
Lysxia / gist:ddf1ea3bb3b81cb7b6965a387c044984
Created February 11, 2019 23:08
infinite random list, with MonadRandom
import Control.Monad.Random
randomList :: MonadRandom m => m [Double]
randomList = do
start <- getRandomR (0.7 :: Double, 1.2)
go start
where go prev = do
new <- getRandomR (min 0.7 (prev-0.1), max (prev+0.1) 1.2)
acc <- go new
return (new : acc)
Axiom bu : bool = unit.
Definition f : bool -> unit :=
match bu in _ = b return bool -> b with
| eq_refl => fun x => x
end.
Definition g : unit -> bool :=
match bu in _ = b return b -> bool with
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
@Lysxia
Lysxia / O.hs
Last active February 19, 2019 12:16
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
import Control.Monad
import Data.Foldable
data Entry a = Any | Every a | Exactly a | Many [a]
deriving (Eq, Ord, Show, Functor, Foldable, Traversable)
Set Implicit Arguments.
Set Contextual Implicit.
Notation TyCon := (Type -> Type).
Inductive Prog {T : Type} (sig : T -> Type -> TyCon) (a : Type) : Type :=
| Ret : a -> Prog sig a
| Op (t : T) : (forall b, sig t a b -> Prog sig b) -> Prog sig a
.
Require Import Coq.Logic.FunctionalExtensionality.
Require Import Coq.Program.Equality.
Class HContainer : Type :=
{
Shape : Type;
Pos : Shape -> Type;
Ctx : forall s : Shape, Pos s -> Type -> Type;
}.
(* Nope, not structurally decreasing *)
Fail Fixpoint f (x y : nat) :=
match x with
| O => O
| S x' => f y x'
end.
(* But looking at f, we can define its domain inductively.
This is literally "the set of x and y for which f is defined",