作者godfat (godfat 真常)
看板PLT
標題Re: [比較] 我為何鍾情於用 Scala 做為兵刃(三)
時間Mon Jul 11 22:23:32 2011
※ 引述《scwg ( )》之銘言:
: ※ 引述《huei1224 (渣)》之銘言:
: : 最近在學 haskell ,發現 haskell 也可以寫成像上面的型式,分享一下
: : let x -: f = f x
: : let xs = [-3..3]
: : let square = (^2)
: : let isGreaterThan5 = (>5)
: : let result = xs -: map square -: filter isGreaterThan5 -: length
: : -- let result = xs -: map (^2) -: filter (>5) -: length
: 通常用 Haskell 的人會這樣寫
: result = length $ filter (>5) $ map (^2) $ xs
: 不過如果想用 flip (.) 的話不如試試
: import Control.Monad.List
: result = length $ xs >>= return . (^2) >>= guard . (>5)
獻醜一下 XD
import Control.Category ((>>>))
result = flip ($)
xs $
map (^2) >>>
filter (>5) >>>
length
--
#!/usr/bin/env ruby [露比] /Programming (Kn|N)ight/ 看板《Ruby》
# if a
dog nailed
extra legs that
http://webptt.com/m.aspx?n=bbs/Ruby/index.html
#
walks like an octopus, and Welcome ~
Ruby@ptt~
#
talks like an octopus, then
◢█◣ http://www.ruby-lang.org/
# we are happy to treat it as
█ http://www.ruby-doc.org/
# if it were
an octopus.
◥ ◤ http://www.rubyforge.org/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.25.231.110
1F:推 scwg:Good thinking :) It's just that I think it's more natural 07/12 02:21
2F:→ scwg:to learn monad before arrow/category. 07/12 02:22
3F:→ godfat:true, thanks! actually i don't really get arrow yet.. 07/12 04:41
4F:推 ccshan:flip ($) xs = ($ xs) 07/12 05:34
5F:→ godfat:good point, thanks! 07/12 15:18