Skip to content

Instantly share code, notes, and snippets.

@xgrommx
xgrommx / _FP reading lists.md
Created March 9, 2017 21:11 — forked from danidiaz/_FP reading lists.md
assorted reading lists

A series of reading lists mostly related to functional programming.

@xgrommx
xgrommx / t.hs
Created March 2, 2017 18:13 — forked from oisdk/t.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
import Data.Functor.Foldable hiding (Foldable)
import qualified Data.Functor.Foldable as Functor
import Data.Traversable
import qualified Data.Map as Map
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
module Data.Functor.Foldable.Monadic
( cataM
, anaM
, futuM
) where
import Protolude
@xgrommx
xgrommx / recursion.hs
Created February 22, 2017 23:52 — forked from YoEight/recursion.hs
Recursion scheme playground
{-# LANGUAGE NoImplicitPrelude #-}
module Origami where
import Prelude
(
(.)
, (-)
, (*)
, (++)
, ($)
@xgrommx
xgrommx / IxFix.hs
Created February 20, 2017 23:32 — forked from AndrasKovacs/IxFix.hs
Example for recursion schemes for mutually recursive data
{-# LANGUAGE
UndecidableInstances, RankNTypes, TypeOperators, TypeFamilies,
StandaloneDeriving, DataKinds, PolyKinds, DeriveFunctor, DeriveFoldable,
DeriveTraversable, LambdaCase, PatternSynonyms, TemplateHaskell #-}
import Control.Monad
import Control.Applicative
import Data.Singletons.TH

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@xgrommx
xgrommx / ListAlgebras.hs
Created February 11, 2017 22:50 — forked from nponeccop/ListAlgebras.hs
RamdaJS reduceBy() in Haskell using recursion-schemes
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Functor.Foldable
import Data.Maybe
import qualified Data.Map as M
listCata :: ListCata a b
listCata = cata
reduceBy :: Ord k => ListAlgebra t b -> (t -> k) -> [t] -> M.Map k b
@xgrommx
xgrommx / gist:881345574f1bc5426dd7a48c308818d0
Created January 16, 2017 22:53 — forked from mikehaertl/gist:3258427
Learn you a Haskell - In a nutshell

Learn you a Haskell - In a nutshell

This is a summary of the "Learn You A Haskell" online book under http://learnyouahaskell.com/chapters.


1. Introduction

  • Haskell is a functional programming language.
@xgrommx
xgrommx / array.chunk.js
Created December 4, 2016 20:02 — forked from webinista/array.chunk.js
Array.prototype.chunk: Splits an array into an array of smaller arrays containing `groupsize` members
/*
Split an array into chunks and return an array
of these chunks.
This will *not* preserve array keys.
*/
Array.prototype.chunk = function(groupsize){
var sets = [], chunks, i = 0;
chunks = this.length / groupsize;
@xgrommx
xgrommx / freefrp.js
Created November 13, 2016 23:52 — forked from jkpl/freefrp.js
Free monad based thread simulation and FRP constructs written in JavaScript. http://stuff.lepovirta.org/r/freefrp/
// Free monad based thread simulation and FRP constructs written in JavaScript
// First, we need some way to express lazy values and actions.
// We can use zero-argument functions for this purpose: call the function and
// you get the value. We also need to compose lazy values/actions. For that
// we have bindLazy function. Lazy values are not expected to be pure
// in this program: evaluating a lazy value/action at different times can produce
// a different value.