Skip to content

Instantly share code, notes, and snippets.

View guibou's full-sized avatar
🛩️
Diving in a sky full of escaped skolems

Carbon based Guibou guibou

🛩️
Diving in a sky full of escaped skolems
  • Saint-Paul - Reunion - France
View GitHub Profile
@guibou
guibou / parser.hs
Created November 8, 2015 10:50
Haskell Parsec Issues
import Text.Parsec
import Text.Parsec.String
import Data.List (groupBy, intersperse)
-- This is a short example of my file format
-- Questions starts with "Q. ", Answers with "A. ". They can span on
-- multiple lines and contain inline markup.
document :: String
document = unlines [
"Q. Question 2.1 can",
@guibou
guibou / ApplicativeParallelIO.hs
Created December 10, 2015 16:38
Simple implementation of parallel IO execution using Applicative
{- | Parallel computation of IO using applicative style
Convert and IO to a Future using *Future*.
You can then use applicative style to combine functions over IO and get a result using 'runFuture'.
Have a look at '<$.>' and '<*.>' for shortcut to avoid wrapping your io with 'Future'.
Exemple:
@guibou
guibou / filter.hs
Created December 28, 2015 15:10
Fun with python to implement function partial application, section and function composition. With the equivalent Haskell version.
assert True = return ()
-- code
l = words "Hello World. How are you today?"
res = words "Hello World. today?"
satisfy f predicate x = predicate (f x)
main = do
assert (filter (\x -> length x > 3) l == res)
@guibou
guibou / test.php
Created July 4, 2016 19:49
Sort in php is not stable
<?php
function print_arr($arr)
{
print "[";
foreach($arr as $val)
{
if(is_array($val))
{
print_arr($val);
import numpy
import time
s = 1000
def monochrome(colors, arr):
r, g, b = colors
blork = arr[:,:,0] * r + arr[:,:,1] * g + arr[:,:,2] * b
return numpy.uint8(blork / (r + g + b))
def stride(n, dims):
'''
Limitations:
- We can go wrong when inverting the order of dimension on
input side but not on result side
>>> (x, y) = stride(10, (8, 5))
>>> x
2
>>> y
#include <stdio.h>
// A node of the list.
struct Node
{
struct Node *next; // the next node
float value; // the contained value
};
// A linked list point to a serie of Node
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE TypeApplications #-}
module NumberDispath where
data Number
= DoubleNum !Double
@guibou
guibou / Expr GADTs.lhs
Last active April 11, 2017 12:15
Using trick from IRC (Thank bartavelle) plus a `formal` proof of injectivity for `MixVar`, this works. No need for Singleton / Bool.
On commence par quelques kilos d'extensions :
> {-# LANGUAGE GADTs, KindSignatures, DataKinds, TypeFamilies, TypeOperators,
> ScopedTypeVariables, FlexibleInstances, ConstraintKinds, PolyKinds,
> StandaloneDeriving, NoMonomorphismRestriction #-}
> {-# OPTIONS -Wall #-}
> module Expr where
Et deux trois imports :
@guibou
guibou / InjectiveOrProof.hs
Created April 6, 2017 10:16
Uncomplete proof of (partial) injectivity of type level (||)
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Type.Equality
import Data.Type.Bool
import Unsafe.Coerce
-- Proof of partial injectivity of (||)
-- i.e.