löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:
loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
where xs = fmap ($ xs) fs
--- | |
title: Compilation as a Typed EDSL-to-EDSL Transformation | |
author: Emil Axelsson | |
colorlinks: blue | |
link-citations: true | |
header-includes: | |
include-before: | |
--- | |
From Edward's comment here - https://www.reddit.com/r/haskell/comments/4cfxri/relationship_between_operational_monad_and_oleg/d1hxmfr | |
You can view Operational f as sugar for Free (Coyoneda f). | |
Coyonedamakes a functor out of anything of kind * -> *. This is good and bad, depending on how you use the result. If you inspect it multiple times and do more fmap's etc, you may wind up lifting and lowering repeatedly and converting back and forth between f and Coyoneda f does require an fmap on the roundtrip. | |
Similarly, Free makes a monad by using any Functor worth of instructions. | |
These notions compose very naturally. Now your 'instructions' don't have to start as a Functor, they just get to be anything of kind * -> *. |
löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:
loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
where xs = fmap ($ xs) fs
type Elem = [String] | |
width :: Elem -> Int | |
width e | |
| (c:_) <- e = length c | |
| otherwise = 0 | |
height :: Elem -> Int | |
height = length |
{-# LANGUAGE DeriveDataTypeable, QuasiQuotes #-} | |
module Main where | |
import Data.Char (toUpper) | |
import Data.List (intersperse) | |
import Data.String.Interpolate (i) | |
import System.Environment (getArgs) | |
main :: IO () | |
main = getArgs >>= putStrLn . makeInsult |
-- This is the configuration file for the 'cabal' command line tool. | |
-- The available configuration options are listed below. | |
-- Some of them have default values listed. | |
-- Lines (like this one) beginning with '--' are comments. | |
-- Be careful with spaces and indentation because they are | |
-- used to indicate layout for nested sections. | |
Requires:
Homebrew (http://mxcl.github.io/homebrew/)
Ruby
Verify Homebrew is not sick:
brew doctor
-- What is the big deal? Took all of 2 minutes to write this | |
module Main where | |
main :: IO () | |
main = mapM_ (putStrLn . fizzbuzz) [1..100] | |
fizzbuzz :: Int -> String | |
fizzbuzz x = divisors `orElse` show x | |
where | |
divisors = concatMap test [(3,"Fizz"),(5,"Buzz"),(7,"Baz")] |
Getting Real | |
============ | |
URL | |
--- | |
http://gettingreal.37signals.com/ | |
Synposis | |
-------- |