[haskell]
addNumber :: String -> String
addNumber s = unlines $ zipWith (numberWithIndent (getIndent ls) (nrWidth $ length ls)) [1..] ls
where ls = lines s
[/haskell]
这段 Haskell 如何弄成 point-free 的?
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
- tangboyun
- 帖子: 701
- 注册时间: 2009-07-25 1:57
- 联系:
Re: 这段 Haskell 如何弄成 point-free 的?
[haskell]
addNumber :: String -> String
addNumber = unlines . (\e -> zipWith (numberWithIndent (getIndent e) (nrWidth $ length e)) [1..]) . lines
[/haskell]
整成这种?难读不少阿,还有就是函数写成这种形式,如果不显式注明签名式的话,而参数又是多态的话,可能会遇到Monomorphism Restriction方面的错误,不知道的话,很难debug。point free除非是那种很短的语句,否则没太大意思的。
addNumber :: String -> String
addNumber = unlines . (\e -> zipWith (numberWithIndent (getIndent e) (nrWidth $ length e)) [1..]) . lines
[/haskell]
整成这种?难读不少阿,还有就是函数写成这种形式,如果不显式注明签名式的话,而参数又是多态的话,可能会遇到Monomorphism Restriction方面的错误,不知道的话,很难debug。point free除非是那种很短的语句,否则没太大意思的。
https://github.com/tangboyun
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 这段 Haskell 如何弄成 point-free 的?
不是,匿名函数里还有参数呢。tangboyun 写了:[haskell]
addNumber :: String -> String
addNumber = unlines . (\e -> zipWith (numberWithIndent (getIndent e) (nrWidth $ length e)) [1..]) . lines
[/haskell]
整成这种?难读不少阿,还有就是函数写成这种形式,如果不显式注明签名式的话,而参数又是多态的话,可能会遇到Monomorphism Restriction方面的错误,不知道的话,很难debug。point free除非是那种很短的语句,否则没太大意思的。
我只是想看看它怎么变成 point free 的,没准备实用的。
- tangboyun
- 帖子: 701
- 注册时间: 2009-07-25 1:57
- 联系:
Re: 这段 Haskell 如何弄成 point-free 的?
你这个要完全去掉太难了,我推了一会儿放弃了。有两个地方有依赖,还都是在一个函数内部的。
我觉得要curry化的话,最好是那种没依赖的。
我觉得要curry化的话,最好是那种没依赖的。
https://github.com/tangboyun
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 这段 Haskell 如何弄成 point-free 的?
知道了:
22:59 <lilydjwg> @pl \s -> let ls = lines s in unlines $ zipWith (numberWithIndent (getIndent ls) (nrWidth $ length ls)) [1..] ls
22:59 <lambdabot> unlines . (flip zipWith [1..] =<< liftM2 numberWithIndent getIndent (nrWidth . length)) . fix . const . lines
- tangboyun
- 帖子: 701
- 注册时间: 2009-07-25 1:57
- 联系:
Re: 这段 Haskell 如何弄成 point-free 的?
这个自动推导牛的。。。要读懂就要在纸上来回推几回了
https://github.com/tangboyun
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。
http://tangboyun.is-programmer.com/
提问的智慧————Eric Steven Raymond
回答的智慧————Andrew Clarke
吾尝终日而思矣,不如须臾之所学也;吾尝跂而望矣,不如登高之博见也。
急急急标题什么的,最讨厌了!
急急复急急,急急何其多,我生待急急,万事急急急。