Skip to content

Instantly share code, notes, and snippets.

There seems to be a lot of confusion around Effects and IO. I wanted to collect a set of questions and answers, and explanations of common misconceptions.

  1. What is an Effect?
  2. What is a Side Effect?
  3. What is a pure function?
  4. What is equational reasoning?
  5. What is an IO?
  6. Is the purpose IO value used to model an effectful computation, such that it can be composed with other computations?
  7. Is Haskell's unsafePerformIO an impure function?
  8. Related: Is it true that forall a, IO a is
/** applyF :: ((a -> b), a) -> b */
public static <A, B> F2<F<A, B>, A, B> applyF() {
return new F2<F<A, B>, A, B>() {
@Override
public B apply(final F<A, B> f, final A a) {
return f.apply(a);
}
};
}
Simon Peyton-Jones
Phillip Wadler
Paul Chiusano
Tony Morris
Mark Hibberd
Edwin Brady
John Carmack
Conor McBride
Evan Czaplicki
Brian McKenna
@techtangents
techtangents / gist:5737508
Last active December 18, 2015 06:08
RE: benkolera: Even though it makes your DSL shiny-ish, overloading functions is a PitA to a FP library user. Please use a sum type instead. #bad #scala etorreborre: @benkolera I'm clearly guilty of this but I don't quite get why it is so bad. Pointers?
Let's use Scala as the implementation language.
Say you have an API function setFoo, that is overloaded for Chook and Dog.
One might call it either of these ways:
setFoo(chook)
setFoo(dog)
As an API user, I wish to call this function from another function
def q(c: Chook) {
@techtangents
techtangents / jenkins.txt
Created April 5, 2013 02:53
How to remove the horrible hover menu popups in Jenkins.
Install "Simple Theme Plugin" - this gives you some theme settings
Configure System > URL of theme CSS = /userContent/noBreadcrumbPopups.css
This maps to something like /var/lib/jenkins/home/userContent/noBreadcrumbPopups.css
Create this file with contents:
#breadcrumb-menu, #breadcrumb-menu * {
display: none !important;
{-
Recall that function composition is:
f . g = f (g x)
Consider, (f . g) as the application of g to an parameter destined for f.
Let's decribe g as the 'mapper' function and f as the 'primary function'
This gist generalises this idea to primary functions of different arities (in curried form).
Each parameter to the primary function has its own mapper function.
The API forms a similar style to that of Applicative, where infix functions chain values together in an expression.
Absolutely:
- any integer
- Incorrect - any integer except Integer.MIN_VALUE
Bytes:
- on each line, the numbers [0..128], [-127..-1]
- Incorrect - infinite loop
Constants:
- characters on lines: STUVWXYZ
@techtangents
techtangents / Cycling.elm
Created March 9, 2013 13:44
A cycling Automaton in Elm. This Automaton produces values off a non-empty list. When the list is exhausted, it starts again. The input signal is just used as a source of events - its values are ignored.
-- non-empty list
data NonEmpty x = NonEmpty x [x]
-- neFromList :: [x] -> NonEmpty x
neFromList list = case list of [] -> Maybe.Nothing
(x:xs) -> Maybe.Just (NonEmpty x xs)
-- neFromListOr :: NonEmpty x -> [x] -> NonEmpty x
neFromListOr other qs = maybeOr other (neFromList xs)
@techtangents
techtangents / counter.elm
Created March 9, 2013 13:06
A signal that counts in whole numbers
const x _ = x
counter = counter' 0
counter' n =
foldp' (\_ s -> s + 1) (const n)
{-# LANGUAGE NoImplicitPrelude, TypeOperators #-}
import Prelude(undefined, Either(..), either, Functor(..))
data Store a b =
Store (a -> b) a
instance Functor (Store a) where
fmap f (Store p g) =
Store (f . p) g