Skip to content

Instantly share code, notes, and snippets.

@zhaar
zhaar / main.idr
Last active November 22, 2019 18:31
module Main
import Data.Vect
import Effects
import Effect.Exception
import Effect.State
ComputeResult : (n ** Fin n) -> List EFFECT
ComputeResult (l ** _) = [EXCEPTION String, STATE (Vect l String)]
import Data.List
%default total
data PathComp : Type where
Empty : String -> PathComp
Printable : (t : Type) -> (t -> String) -> PathComp
Str' : PathComp
Str' = Printable String id
|||build a type signature out of a list of types
||| e.g.: `ListToSig [String, Int, Int]` returns String -> Int -> Int -> String
ListToSig : List Type -> Type
ListToSig [] = String
ListToSig (x :: xs) = x -> ListToSig xs
||| returns a function that builds a string from the arguments given to it
||| e.g.: `listToFunc [(String, show), (Int, show)] ""` returns a function f : String -> Int -> String
||| and when applied with input `f "hello" 3` gives "hello.3."
%default total
data Prop = Var String
| Not Prop
| And Prop Prop
| Or Prop Prop
| Impl Prop Prop
| Equiv Prop Prop
data Lit = Stmt String | Neg String
%default total
data Prop = Var String
| Not Prop
| And Prop Prop
| Or Prop Prop
| Impl Prop Prop
| Equiv Prop Prop
data Lit = Stmt String | Neg String
@zhaar
zhaar / tress.idr
Last active August 18, 2017 00:31
import Data.Vect
data Ast a = ASTLeaf a | NonASTLeaf a (Vect k $ Ast a)
data TypedAst : Type where
LLeaf : (a : String) -> TypedAst
NonTLeaf : (a : String) -> Vect k TypedAst -> TypedAst
Op : Type
data IR = IRLeaf Op | NonLeaf Op (Vect k IR)
public static Function<List<Float>, List<Float>> sobelDoubleConvolution(int width, int height) {
int[][] hSobel = {{0, 1, 0}, {0, 0, 0}, {0, -1, 0}};
int[][] vSobel = {{0, 0, 0}, {1, 0, -1}, {0, 0, 0}};
ImageTransformation<Float, Float> vertical = ImageTransformation.convolutionTransformation(vSobel, 3, width, height);
ImageTransformation<Float, Float> horizontal = ImageTransformation.convolutionTransformation(hSobel, 3, width, height);
return vertical.mergeWith(horizontal, MyList::zip)
.andThen(ls -> ls.parallelStream().map(Convolution::distance).collect(Collectors.toList()));
}
//Sane signature: Acc -> (Acc, [(Int, Int)]) the list of pair returned contains the index and the amount of votes associated
public static Function<HoughAccInterface, Pair<HoughAccInterface, List<Pair<Integer, Integer>>>> mapToClusters(int minVotes, int neighborhood) {
return hough -> {
//Sane: [(Int, Int)] -> (Int, Int) -> [(Int, Int)]
BiFunction<List<Pair<Integer, Integer>>, Pair<Integer, Integer>, List<Pair<Integer, Integer>>> accumulator = (acc, pair) -> {
int votes = pair._1();
int index = pair._2();
Pair<Integer, Integer> coord = hough.convertIndex(index);
if (votes > minVotes && isLocalMaxima(hough, coord._1(), coord._2(), neighborhood)) {
acc.add(new Pair<>(index, votes));
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[nodes near coords,
ytick=data,
xtick=data,
//You can put those functions in an external file. Call it for example "Utilities.swift"
//Random number between ranges
func random(min min: Int, max: Int) -> Int {
return Int(arc4random_uniform(UInt32(max - min))) + min
}
func random(range: Range<Int>) -> Int {
return random(min: range.startIndex, max: range.endIndex)
}