Groups
Groups
Sign in
Groups
Groups
haskell.cn
Conversations
About
Send feedback
Help
Haskell 中的 for 循环实现
263 views
Skip to first unread message
Lee
unread,
Apr 12, 2008, 11:29:15 PM
4/12/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskell.cn
如下是一个较通用的 Haskell 的 for 循环实现:
for :: a -> (a->Bool) -> (a->a) -> (a->IO ()) -> IO ()
for i p f job
| p i = do
job i
for (f i) p f job
| otherwise = return ()
Haskell 之所以没有在语言本身或者说 Prelude 中提供 for 循环,是因为 for 这种
顺序执行的特性和 Functional Programming 本身是有冲突的。
例子:
for i (<10) (+1) (print)
一千瓦的刀狼
unread,
Apr 13, 2008, 5:18:00 AM
4/13/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskell.cn
给一个链接,那里给出了好多答案,呵呵。
http://groups.google.com/group/comp.lang.haskell/browse_thread/thread/3882d6756dba11be#
Lee
unread,
Apr 16, 2008, 9:53:16 AM
4/16/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskell.cn
On Apr 13, 5:18 pm, 一千瓦的刀狼 <
knifew...@gmail.com
> wrote:
> 给一个链接,那里给出了好多答案,呵呵。
>
>
http://groups.google.com/group/comp.lang.haskell/browse_thread/thread.
..
嗯,那个只是我看 Haskell Wikibook 时做的一道习题。
BTW,我再多说一句,你给的链接我看了,对于你的问题,comp.lang.haskell 列表中的许多人都热情回复了,可你发问后却无影无踪
了,
这是相当不礼貌的行为,不论那些回复的人是否帮到了你(而且他们确实帮到了你),跟贴说一下你看到了他们的回复并不困难吧?再说,
道声谢并不费什么事吧?
lee
Lee
unread,
Apr 16, 2008, 10:00:19 AM
4/16/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskell.cn
On Apr 13, 11:29 am, Lee <
lee.du...@gmail.com
> wrote:
> 如下是一个较通用的 Haskell 的 for 循环实现:
看看 Control.Monad 相当的有帮助:
http://hackage.haskell.org/packages/archive/
base/
3.0.0.0/doc/html/Control-Monad.html
lee
Reply all
Reply to author
Forward
0 new messages