作者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/cn.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