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
{-# OPTIONS_GHC -fglasgow-exts #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
data S a | |
data Z | |
newtype Number s = Num () | |
class AsInt n where | |
asInt :: Number n -> Int |
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.Monoid | |
type State s a = s -> (a,s) | |
get :: State s s | |
set :: s -> State s () | |
get s = (s,s) | |
set s _ = ((),s) |
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
all: anagram | |
anagram: anagram.hs | |
ghc --make anagram.hs # -O2 -funbox-strict-fields | |
FILE=/usr/share/dict/words | |
bench: anagram | |
time ruby ./anagram.rb < $(FILE) | |
time ./anagram < $(FILE) |
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 System.Directory | |
orElse :: Maybe a -> Maybe a -> Maybe a | |
orElse x y = maybe y Just x | |
orElseM :: (Monad m) => m (Maybe a) -> m (Maybe a) -> m (Maybe a) | |
orElseM x y = maybe y (return . Just) =<< x | |
findJust :: [Maybe a] -> Maybe a | |
findJust = foldr orElse Nothing |
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
= | |
GHC 6.12 の Unicode I/O | |
Yusaku Hashimoto | |
<[email protected]> | |
- | |
自己紹介 | |
- | |
京都の組み込み系専門学生の | |
皮をかぶった Haskeller |
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
nobsun: ここはHaskellプログラミングに興味をもつ人が,とりとめなく,おしゃべりをする場所です。 | |
nobsun: またり部屋も用意してあります。> http://chaton.haskell.jp/matari/ | |
nobsun: そろそろですね。 | |
nobsun: 進行をどうするかちゃんと考えていませんが、「副作用」とその周辺の話題について、とりとめなくやりたいとおもいます。 | |
nobsun: 「副作用がなくてなぜゲームが書けるのか」というところからはじめましょう。 | |
fubabz: こんばんは | |
kazu: こんばんは。 | |
nobsun: この疑問を誘発しているのは「Haskellは副作用がない」という宣伝だと思っているのですが。そうですか? | |
nobsun: こんばんは | |
kazu: そうです。 |
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 DeriveDataTypeable #-} | |
module Expr where | |
import Data.Maybe | |
import Data.Generics | |
import Control.Monad | |
import Control.Applicative | |
import Test.QuickCheck |
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
19:40 himabot: Applicative かわいいよ Applicative | |
19:49 kazu_: てすと | |
19:50 himabot: HIMA はじまりますよー (今回は Typeclassopedia をあがめ奉る会です) | |
19:59 kazu_: 始めますかー。 | |
19:59 kazu_: こっちは、Typeclassopedia です。 | |
20:00 himabot: HIMA はじめますよー (今回は Typeclassopedia を吊るし上げる会です) | |
20:00 kazu_: どう進めます? | |
20:00 nwn: どうしましょうか | |
20:00 kazu_: バラバラと質問を書いて行く? | |
20:01 kazu_: あるいは、論文を上から順に進んで、適宜質問を出す? |
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 Control.Applicative | |
import Control.Monad | |
import Data.Maybe | |
-- Line oriented parser | |
newtype Awky a = Awky { app :: String -> Maybe a } | |
f :: Int -> Awky String | |
f n = Awky $ \str -> let ws = words str; len = length ws | |
in guard (n < len) >> Just (ws !! n) |
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 Control.Applicative | |
import Control.Arrow | |
-- foldr-version of http://squing.blogspot.com/2008/11/beautiful-folding.html | |
data Fold a c = forall b. Fold (a -> b -> b) b (b -> c) | |
runFold :: Fold a c -> [a] -> c | |
runFold (Fold cons nil c) ls = c . foldr cons nil $ ls | |
both :: Fold a c -> Fold a c' -> Fold a (c,c') |