- http://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
- http://pragprog.com/magazines/2012-09/thinking-functionally-with-haskell
- http://pragprog.com/magazines/2012-10/thinking-functionally-with-haskell
- http://pragprog.com/magazines/2012-11/thinking-functionally-with-haskell
- http://pragprog.com/magazines/2012-12/web-programming-in-haskell
- http://pragprog.com/magazines/2013-01/web-programming-in-haskell-part-ii
- http://pragprog.com/magazines/2013-03/uncle-bob-and-functional-programming
- http://pragprog.com/magazines/2013-04/dependent-types
- http://pragprog.com/magazines/2013-05/dependent-types-part-ii
- http://pragprog.com/magazines/2013-06/unification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
placeholder... until a few more days into July | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- using Haskell's library for rational numbers, which stores a rational as | |
-- a pair of integer numbers (not limited to 32 or 64 bits); hence able to do | |
-- exact arithmetic etc up to high numbers | |
import Data.Ratio | |
-- the core function: spits out a list of ascending n for the fractions | |
-- works by reducing (a/b) to 1/ceil(b/a) + ... | |
fractionize t | |
| t == 0 = [] | |
| diff >= 0 = next : fractionize diff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List(nub, sortBy, groupBy) | |
import Data.Char(isAlpha, toLower) | |
isograms s | |
= [ (length w, w) | |
| w <- nub $ words $ map toLower s | |
, all isAlpha w | |
, nub w == w ] | |
main = do text <- readFile "pg11.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (elemIndex) | |
tests :: (Int -> String -> String) -> [Bool] | |
tests wrap | |
= [ wrap 1 "" == "" | |
, wrap 1 "x" == "x" | |
, wrap 1 "xx" == "x\nx" | |
, wrap 1 "xxx" == "x\nx\nx" | |
, wrap 1 "x x" == "x\nx" | |
, wrap 2 "x x" == "x\nx" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- see below for commentary | |
makeUpTo :: Int -> [String] -> [String] | |
makeUpTo n = mlu [] | |
where | |
mlu pre [] = [pre] | |
mlu [] (w:ws) = mlu w ws | |
mlu pre (w:ws) | length pre + 1 + length w <= n = mlu (pre ++ ' ' : w) ws | |
| otherwise = pre : mlu [] (w:ws) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE NoImplicitPrelude #-} | |
{-# LANGUAGE NoMonomorphismRestriction #-} | |
-- Example for December 2012 Prag Pub Magazine | |
-- expects Fay 0.10 | |
-- | |
-- Fay doesn't support type classes yet (hopefully soon) so this code contains | |
-- various workarounds and so is a bit more complex than it should be! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aahs | |
abbe | |
abbr | |
abed | |
abet | |
able | |
ably | |
abut | |
acct | |
aced |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- word list is at https://gist.github.com/3799331 | |
import Data.Set(Set, fromDistinctAscList, member) | |
import System.IO.Unsafe(unsafePerformIO) | |
import Data.Tree | |
import Data.List(inits,tails) | |
-------------------- | |
-- first step - generating valid next words |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- compiles with ghc(i) 7.4.1 | |
import Data.Map (Map, empty, insertWith, toList) | |
import Data.List(groupBy, group, sortBy, sort) | |
{- To recap from the main article, we want to define "group_on" via "groupBy", so that its | |
type is something like (b -> b -> Bool) -> (a -> b) -> [a] -> [(b, [a])] | |
The method here is to work with a concrete example and gradually massage it | |
into the form we want - using the REPL |
NewerOlder