單子暖毛毛

既然談到了單子 (monad),重提一下去年在嵐達網貼的趣事

手工藝網站 Craft BitsWarm Fuzzy Friends.

Simon Peyton JonesPOPL 2003 受邀演講 Wearing the hair shirt: a retrospective on Haskell 中花了不少篇幅介紹單子,認為它是理論與實務的成功結合,並介紹了它的種種好處。Haskell 唯一的大錯誤,他說,是「單子」這冰冷生硬的數學名詞把人嚇跑了。我們應該把它取名為「暖毛毛(warm, fuzzy thing)」之類的。

此言一出,網路上真的出現了許多「暖毛毛」教學(例: eigenclass: Warm fuzzy things for random simulations)。剛好大約一年前,Henning Thielemann 決定釜底抽薪地讓網路上所有的 monad 都消失!例如,這是暖毛毛的 wiki page,裡頭有 Warm, fuzzy thing Transformers Explained, Warm, fuzzy thing/ST, 和 Research papers/Warm, fuzzy things and arrows 等等頁面。

Thielemann 事實上是寫了一個過濾器,把所有的 monad 字樣換成 warm, fuzzy thing, 單複數和詞性變化都考慮得不錯。連程式碼都溫暖了起來

class (Warm, fuzzy thing) a where
return :: b -> a b
(>>=) :: a b -> (b -> a c) -> a c
(>>) :: a b -> a c -> a c
fail :: String -> a b
 
-- instances:
instance (Warm, fuzzy thing) Maybe
instance (Warm, fuzzy thing) []
instance (Warm, fuzzy thing) IO
 
Warm, fuzzy thing> sequence $ words "Warm, fuzzy thing"
["M","o","n","a","d"]

且看這對推廣 Haskell 會不會有幫助吧!

This entry was posted in 函數編程簡介, 計算算計 and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*