Skip to content

Instantly share code, notes, and snippets.

/* A table of factorials. table[i] is the factorial of i. The
* max field is calculated so that its factorial would not be an
* integer overflow.
*/
typedef struct {
unsigned max;
unsigned *table;
} factorial_table;
var findByTitle: (String) -> (MutableList<Movie>) -> List<Movie> =
{ query -> { collection ->
val predicate = matches(query)
filter(predicate)(collection)
}}
val filter: ((Movie) -> Boolean) -> (List<Movie>) -> List<Movie> =
{ predicate -> { collection ->
collection.filter(predicate)
}}
var findByTitle: (String) -> (MutableList<Movie>) -> List<Movie> =
{ query -> { collection ->
val predicate = matches(query)
filter(predicate)(collection)
}}
val filter: ((Movie) -> Boolean) -> (List<Movie>) -> List<Movie> =
{ predicate -> { collection ->
collection.filter(predicate)
}}
@clojj
clojj / main.hs
Created October 12, 2018 20:48
InsistentLazyRedundantcode created by anonymous - https://repl.it/repls/InsistentLazyRedundantcode
gcdHaskell :: Int -> Int -> Int
gcdHaskell x y | x > y = gcdHaskell (x - y) y
| x < y = gcdHaskell x (y - x)
| otherwise = x
main = print $ gcdHaskell 4 2
@clojj
clojj / ttt.idr
Created October 13, 2017 14:35
fresh start on typed tic tac toe
module TicTacToe
import Data.Vect
data Piece = X | O | N
next : Piece -> Piece
next X = O
next O = X
next N = N
@clojj
clojj / tictactoe.idr
Last active October 12, 2017 21:05
Idris type-level tic-tac-toe
module TicTacToe
import Data.Vect
||| All possible player pieces, where N represents empty
data Piece = X | O | N
||| Select next player
next : Piece -> Piece
next X = O
module TicTacToe
import Data.Vect
||| All possible player pieces, where N represents empty
data Piece = X | O | N
||| Select next player
next : Piece -> Piece
next X = O
@clojj
clojj / gist:216a7d274878420ac053
Created April 20, 2015 15:09
parallel grep recursively for STRING-content (requires GNU parallel package)... replace STRING with what you are looking for !
find . -type f | parallel -k -j150% -n 1000 -m grep -i -H -n 'STRING' {}
@clojj
clojj / compose.hs
Last active January 26, 2017 15:04
compose function from list of functions
import Data.List
compose :: [a -> a] -> a -> a
compose fs v = foldl' (flip (.)) id fs $ v
@clojj
clojj / compose-maybe-functions.hs
Last active January 26, 2017 10:40
compose list of Maybe functions
import Data.List
compose :: [Maybe (a -> a)] -> a -> a
compose fs v = foldl' compf id fs $ v
compf :: (a -> a) -> Maybe (a -> a) -> (a -> a)
compf f mg =
case mg of
Nothing -> f
Just g -> g . f