大家好,问个关于Ass 2 关于FP语法的问题

35 views
Skip to first unread message

Paul liu

unread,
Oct 4, 2012, 4:30:54 PM10/4/12
to fp...@googlegroups.com
那个exists和forall 的关系我能想到,可是我不知道怎么pass negative condition p as parameter?

直接pass "!p" into forall 没有办法编译,网上查资料也没有头绪。。。

不知道是我哪里没有弄明白?

谢谢先。

kwong ho

unread,
Oct 4, 2012, 11:37:25 PM10/4/12
to fp...@googlegroups.com
forall suppose to take in a set and a condition p
forall ( s, !p)?

Paul liu

unread,
Oct 5, 2012, 12:08:47 AM10/5/12
to fp...@googlegroups.com
value unary_! is not a member of Int => Boolean FunSets.scala /progfun-funsets/src/main/scala/funsets

我也是这么想的,不过无法编译,不知道哪里的问题。。。

Xianming Mu

unread,
Oct 5, 2012, 3:01:04 AM10/5/12
to fp...@googlegroups.com
如果直接把!p当做参数就会出现你提到的那个编译错误。
实际上应该是把p的返回值取反:

x => !p(x)

这样就没问题了。


--
You received this message because you are subscribed to the Google Groups "fp-cn" group.
To post to this group, send email to fp...@googlegroups.com.
To unsubscribe from this group, send email to fp-cn+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/fp-cn?hl=en.
 
 



--
Regards,

Samuel

Paul liu

unread,
Oct 5, 2012, 3:14:55 AM10/5/12
to fp...@googlegroups.com
是了,这个问题真的很弱智:D

Xianming Mu

unread,
Oct 5, 2012, 3:25:22 AM10/5/12
to fp...@googlegroups.com
这种函数式思维确实挺绕人的,我做那题的时候做到脑子疼。

Paul liu

unread,
Oct 5, 2012, 3:45:17 AM10/5/12
to fp...@googlegroups.com
概念太抽象,题目很纠结,不过我觉的对我最花时间是Scala的语法,不知道各位有没有看/买作者的 Programming in Scala 2nd Ed?还有很多人推荐的SICP?
后者免费,不过我觉得有些偏抽象,看的时候还有对Scheme语法的不适应,感觉这个课的直接帮助不大,前一本不知道有没有人看过?

Xianming Mu

unread,
Oct 5, 2012, 4:43:29 AM10/5/12
to fp...@googlegroups.com

2012/10/5 Paul liu <psta...@gmail.com>

概念太抽象,题目很纠结,不过我觉的对我最花时间是Scala的语法,不知道各位有没有看/买作者的 Programming in Scala 2nd Ed?还有很多人推荐的SICP?
后者免费,不过我觉得有些偏抽象,看的时候还有对Scheme语法的不适应,感觉这个课的直接帮助不大,前一本不知道有没有人看过?

 
Programming in Scala还没看,我看了那本Scala for impatient和twitter的Scala School(http://twitter.github.com/scala_school/),觉得针对这课来说够用了。
SICP打算上完这课再看看,以前只看过前两章,讲递归和迭代那块,感觉这门课的思想和它差不多,后面不知道写的怎么样,网上倒是很多人推崇。

以前看过一篇讲函数式思想的文章,感觉挺不错的,在这也分享下,http://www.defmacro.org/ramblings/fp.html

Paul liu

unread,
Oct 5, 2012, 5:05:55 AM10/5/12
to fp...@googlegroups.com
感谢分享,原来你说的函数式分享是这个。按理说学Scala语法应该不是问题,我这个人记性不好,看过的编程语言比较杂,而Scala和Java和Scheme都有点象,
我两个都不太熟了(Java都还老师了,Scheme现学现用),就混了。。。倒是这个函数式思路真的不容易学,入门难,学透好像也很难,关键是大家日常用的编程
语言走的路子很不一样。SICP感觉是很大牛的书,我只看了一章半,已经感觉对对具体编程语言之外的东西有点收获了,可是不做题的话,没信心能一直看下去,
而不是读天书。

Paul liu

unread,
Oct 5, 2012, 5:08:58 AM10/5/12
to fp...@googlegroups.com
还有一种方法:
!p(_)
'_'是anonymous function里面的placeholder.

我也是看来的:D

Xianming Mu

unread,
Oct 5, 2012, 6:51:23 AM10/5/12
to fp...@googlegroups.com
嗯,这么写更简洁。大部分需要写一个匿名函数做参数的情况下都可以用_代替。

kwong ho

unread,
Oct 5, 2012, 7:44:59 AM10/5/12
to fp...@googlegroups.com
wow ~~ nice one liner~

yfaming

unread,
Oct 8, 2012, 8:15:48 AM10/8/12
to fp...@googlegroups.com
建议看《Scala by Exmaple》吧,一百多页,短小精悍,与课程内容也比较同步,作者正是Martin Odersky

Xianming Mu

unread,
Oct 8, 2012, 8:45:19 AM10/8/12
to fp...@googlegroups.com


2012/10/8 yfaming <yfa...@gmail.com>

建议看《Scala by Exmaple》吧,一百多页,短小精悍,与课程内容也比较同步,作者正是Martin Odersky


 
多谢分享。浏览了一下确实是啊,好多例子讲课的时候都出现过,sumInt,EmptySet什么的 。
话说已经上了两周课之后我才知道原来Scala的作者就是Martin Odersky……立刻肃然起敬了。

Reply all
Reply to author
Forward
0 new messages