Skip to content

Instantly share code, notes, and snippets.

View bruno-cadorette's full-sized avatar

Bruno Cadorette bruno-cadorette

  • Sherbrooke
  • 16:55 (UTC -04:00)
View GitHub Profile
import Control.Applicative
import qualified Data.Map as Map
import Debug.Trace
import Data.Foldable
import Data.Maybe
import Data.Ord
import Data.List
import Data.List.NonEmpty (nonEmpty)
minTransitions ::
@bruno-cadorette
bruno-cadorette / removelast.coq
Created January 10, 2020 22:40
remove last algorithm equivalence proof
Require Import Coq.Lists.List.
Import Coq.Lists.List.ListNotations
Fixpoint my_remove_last {A : Type} (l : list A) : list A:=
match l with
| [] => []
| x :: [] => []
| x :: xs => x :: (my_remove_last xs)
end.
@bruno-cadorette
bruno-cadorette / gist:5ea827c8b0677a6e63adbf60688e1ca8
Last active November 9, 2018 04:51
binary tree insertion using paramorphism
{-#LANGUAGE TypeFamilies, DeriveFunctor #-}
import Data.Functor.Foldable
data Tree a = Leaf | Node a (Tree a) (Tree a) deriving (Show)
data TreeF a b = LeafF | NodeF a b b deriving (Functor, Show)
type instance Base (Tree a) = TreeF a
instance Recursive (Tree a) where
project Leaf = LeafF
### Keybase proof
I hereby claim:
* I am bruno-cadorette on github.
* I am brunocadorette (https://keybase.io/brunocadorette) on keybase.
* I have a public key ASDpLETUCCZ5yGWHBeGCTPt9d-RKxIOW9NeZIYe1nvICNgo
To claim this, I am signing this object:
@bruno-cadorette
bruno-cadorette / index.js
Created August 15, 2017 03:03
Download a facebook conversation!
/*
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
@bruno-cadorette
bruno-cadorette / Maybe.cs
Created April 27, 2016 09:37
Haskell like maybe in C#. Contains functor, applicative functor and monad implementation. Do not use this in real code, C# 6.0 have the ?. operator that is nearly the same thing
using System;
namespace MaybeCSharp
{
interface IMaybe<T>
{
IMaybe<U> Bind<U>(Func<T, IMaybe<U>> f);
IMaybe<U> Map<U>(Func<T, U> f);
IMaybe<U> Ap<U>(IMaybe<Func<T, U>> f);
}
import Keyboard
import Mouse exposing (position)
import Time exposing (Time, fps)
import Debug exposing(..)
import Signal
import Graphics.Element exposing (show)
import Graphics.Collage
import Color exposing (red, black)
import Window exposing (dimensions)
@bruno-cadorette
bruno-cadorette / HierachicalParser.hs
Created November 9, 2015 05:38
Read a rose tree separated by new lines and tabs and transform it to a Data.Tree
import Data.List
import Data.Tree
import Control.Arrow (first)
import Data.Function (on)
toHierarchical :: String -> [(Int, [String])]
toHierarchical = map simplify . groupBy ((==) `on` fst) . map (first length . span (== '\t')) . lines
where
simplify = first head . unzip
using System;
namespace CSharpFunctional
{
[Serializable]
public class NoPatternException : Exception
{
public NoPatternException() { }
public NoPatternException(string message) : base(message) { }
public NoPatternException(string message, Exception inner) : base(message, inner) { }
@bruno-cadorette
bruno-cadorette / RPSGame.hs
Last active August 29, 2015 14:23
Rock paper scissor
import Text.Read (readMaybe)
import System.Random (randomRIO)
data Move = Rock | Paper | Scissor deriving(Eq, Read, Show, Enum)
data Result = Victory | Defeat | Draw deriving(Show)
play Rock Scissor = Victory
play Paper Rock = Victory
play Scissor Paper = Victory
play a b