This is a summary of the "Learn You A Haskell" online book under http://learnyouahaskell.com/chapters.
- Haskell is a functional programming language.
%.coffee: %.coffee.md | |
sed -n -e '/^ \{4\}/s/^ \{4\}//p' $< > $@ | |
%.js: %.js.md | |
sed -n -e '/^ \{4\}/s/^ \{4\}//p' $< > $@ | |
%.js: %.coffee | |
coffee -cb $< | |
all: multi-inherit.coffee multi-inherit.future.js | |
clean: |
// 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. |
/* | |
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; |
This is a summary of the "Learn You A Haskell" online book under http://learnyouahaskell.com/chapters.
{-# 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 |
Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.
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
{-# LANGUAGE | |
UndecidableInstances, RankNTypes, TypeOperators, TypeFamilies, | |
StandaloneDeriving, DataKinds, PolyKinds, DeriveFunctor, DeriveFoldable, | |
DeriveTraversable, LambdaCase, PatternSynonyms, TemplateHaskell #-} | |
import Control.Monad | |
import Control.Applicative | |
import Data.Singletons.TH | |
{-# LANGUAGE NoImplicitPrelude #-} | |
module Origami where | |
import Prelude | |
( | |
(.) | |
, (-) | |
, (*) | |
, (++) | |
, ($) |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module Data.Functor.Foldable.Monadic | |
( cataM | |
, anaM | |
, futuM | |
) where | |
import Protolude |
{-# 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 |