Redian新闻
>
请教大牛和小牛帮助菜鸟ML编程问题!
avatar
请教大牛和小牛帮助菜鸟ML编程问题!# Programming - 葵花宝典
y*e
1
1.回国带烟有什么限制吗?
2.怎么在机场买免税烟啊?一般什么机场有?
3.听说在飞机上也可以买免税烟?我是坐continental的飞机,也可以买到吗?一般飞
机上都有卖的吗?
4.现在一般带什么烟回国内比较好?
avatar
n*h
2
显卡已经正确识别了? Quadro FX 3700。
可是看起来还是卡卡的,网页如果有图片拖动就会很慢?
avatar
k*t
3
Write a function increasing: int list -> bool that returns true if its
input is a list of integers in increasing order.
Define function addOneToAll(x, L) that takes a value
x and add it to all the elements in L, which is a list of lists.
For example, addOneToAll(1, [nil, [2], [3], [2,3]]) = [[1], [1,2], [1,3], [1
,2,3]].
才开始学编程,这两个怎么写啊?
第二个题,我写了这样的可是不工作:
-fun addOneToAll(a,nil)=nil
|fun addOneToAll(a,[x]::[y]::nil)=(a::[x])::addOneToAll(a,[y]::nil)::nil;
希望大家帮我。
avatar
a*e
4
1,好像没有
2,机场免税店,有国际航线的一般都有
3,是,国际航班都有
4,古巴雪茄
avatar
r*w
5
装显卡驱动了吗?
avatar
k*t
6
:(no one knows?
avatar
q*2
7
You can buy it at PVG or PEK after arrival before reaching the custom.
avatar
n*h
8
No. I guess this might be the problem.
I assume the video card is OK once recognized by the system.

【在 r*********w 的大作中提到】
: 装显卡驱动了吗?
avatar
G*l
9
不懂ML,用同样ML family的F#解答一下,你应该可以看明白
第一个问题,思路:list为空的时候怎么办?list只有一个的时候怎么办?list有多个
的时候怎么办?
let rec IsMonoIncreasing = function
| [] -> true
| first::second::remain ->
match second > first with
| false -> false
| true -> IsMonoIncreasing (second::remain)
| singleElement::[] -> true
注意为什么要把至少2个的情况放在只有一个的情况前面。
第二个就不写code了,不过x::y::nil应该match的是只有两个元素的list吧?你应该
match用 x::remain

[1

【在 k***t 的大作中提到】
: Write a function increasing: int list -> bool that returns true if its
: input is a list of integers in increasing order.
: Define function addOneToAll(x, L) that takes a value
: x and add it to all the elements in L, which is a list of lists.
: For example, addOneToAll(1, [nil, [2], [3], [2,3]]) = [[1], [1,2], [1,3], [1
: ,2,3]].
: 才开始学编程,这两个怎么写啊?
: 第二个题,我写了这样的可是不工作:
: -fun addOneToAll(a,nil)=nil
: |fun addOneToAll(a,[x]::[y]::nil)=(a::[x])::addOneToAll(a,[y]::nil)::nil;

avatar
y*e
10
这个没法子了,我从成都入关

【在 q*******2 的大作中提到】
: You can buy it at PVG or PEK after arrival before reaching the custom.
avatar
n*h
11
就是驱动问题,谢谢

【在 n******h 的大作中提到】
: No. I guess this might be the problem.
: I assume the video card is OK once recognized by the system.

avatar
k*t
12
太谢谢了。我会顺着你的思路再看看。

【在 G***l 的大作中提到】
: 不懂ML,用同样ML family的F#解答一下,你应该可以看明白
: 第一个问题,思路:list为空的时候怎么办?list只有一个的时候怎么办?list有多个
: 的时候怎么办?
: let rec IsMonoIncreasing = function
: | [] -> true
: | first::second::remain ->
: match second > first with
: | false -> false
: | true -> IsMonoIncreasing (second::remain)
: | singleElement::[] -> true

avatar
y*e
13
网上哪有比较好的卖古巴雪茄的地方?

【在 a****e 的大作中提到】
: 1,好像没有
: 2,机场免税店,有国际航线的一般都有
: 3,是,国际航班都有
: 4,古巴雪茄

avatar
p*3
14

[1
想歪了,面壁...

【在 k***t 的大作中提到】
: Write a function increasing: int list -> bool that returns true if its
: input is a list of integers in increasing order.
: Define function addOneToAll(x, L) that takes a value
: x and add it to all the elements in L, which is a list of lists.
: For example, addOneToAll(1, [nil, [2], [3], [2,3]]) = [[1], [1,2], [1,3], [1
: ,2,3]].
: 才开始学编程,这两个怎么写啊?
: 第二个题,我写了这样的可是不工作:
: -fun addOneToAll(a,nil)=nil
: |fun addOneToAll(a,[x]::[y]::nil)=(a::[x])::addOneToAll(a,[y]::nil)::nil;

avatar
p*2
15
第一题
(defn f [list & args]
(let [f (first list) r (rest list) [prev] args]
(cond (empty? list) true
(nil? prev) (dfs f r)
(< prev f) (dfs f r)
:default false)))
avatar
p*2
16
第二题
(defn f [x list] (map #(cons x %) list))
avatar
G*l
17
你这是lisp family的语言吧?lisp跟ML差别还是很大的。没学过lisp的不太可能看的
懂。楼主一看就是初学者。

【在 p*****2 的大作中提到】
: 第一题
: (defn f [list & args]
: (let [f (first list) r (rest list) [prev] args]
: (cond (empty? list) true
: (nil? prev) (dfs f r)
: (< prev f) (dfs f r)
: :default false)))

avatar
p*2
18

这样呀。我不懂ml。主要的区别是啥呀?我以为思想都差不多呢。

【在 G***l 的大作中提到】
: 你这是lisp family的语言吧?lisp跟ML差别还是很大的。没学过lisp的不太可能看的
: 懂。楼主一看就是初学者。

avatar
G*l
19
那java和lisp主要差别是啥呀?差别很大的两个语言,这个话题一两句话哪说的清。
但你看看我前面F#写的code,和你那个lisp完全不同吧。

【在 p*****2 的大作中提到】
:
: 这样呀。我不懂ml。主要的区别是啥呀?我以为思想都差不多呢。

avatar
p*2
20

你那个我能看懂 跟我的差不多 就是有点不简练

【在 G***l 的大作中提到】
: 那java和lisp主要差别是啥呀?差别很大的两个语言,这个话题一两句话哪说的清。
: 但你看看我前面F#写的code,和你那个lisp完全不同吧。

avatar
G*l
21
反正我要是没学过lisp,你那个我绝对看不懂。
不过lisp说别人不简练?F#的7行,你lisp的9行。不考虑我定义的变量名的长度的话,
每行也比你短吧。

【在 p*****2 的大作中提到】
:
: 你那个我能看懂 跟我的差不多 就是有点不简练

avatar
p*2
22

我感觉lisp跟java的差别,比lisp跟ml的差别大多了。
你就是用了个pattern matching吧。我是觉得应该看看怎么把有一个元素和没有元素的
情况合并一下。倒不是说行数。

【在 G***l 的大作中提到】
: 反正我要是没学过lisp,你那个我绝对看不懂。
: 不过lisp说别人不简练?F#的7行,你lisp的9行。不考虑我定义的变量名的长度的话,
: 每行也比你短吧。

avatar
G*l
23
这不是要写的最简单最直观,让初学者看的懂嘛。
用lisp family的scheme写一个:
(define (isMonoInc? x)
(cond
((or (null? x) (null? (cdr x))) #t)
((< (car x) (car (cdr x))) (isMonoInc? (cdr x)))
(else #f)))

【在 p*****2 的大作中提到】
:
: 我感觉lisp跟java的差别,比lisp跟ml的差别大多了。
: 你就是用了个pattern matching吧。我是觉得应该看看怎么把有一个元素和没有元素的
: 情况合并一下。倒不是说行数。

avatar
p*2
24

我也把我的程序update了一下,6行。
你刚才怎么说看不懂我的?你不是会lisp吗?

【在 G***l 的大作中提到】
: 这不是要写的最简单最直观,让初学者看的懂嘛。
: 用lisp family的scheme写一个:
: (define (isMonoInc? x)
: (cond
: ((or (null? x) (null? (cdr x))) #t)
: ((< (car x) (car (cdr x))) (isMonoInc? (cdr x)))
: (else #f)))

avatar
G*l
25
我是说如果我不会lisp。。。
ml也可以写的很简洁,但是初学者可能看不懂
let rec IsMonoInc = function
| [] -> true
| [f] -> true
| f::((s::_)as remain) -> if f >= s then false else IsMonoInc(remain)

【在 p*****2 的大作中提到】
:
: 我也把我的程序update了一下,6行。
: 你刚才怎么说看不懂我的?你不是会lisp吗?

avatar
p*2
26

这样呀。你到提醒我应该去看一下clojure的pattern matching了,刚发现他们也有一
个。一会儿瞧瞧去。

【在 G***l 的大作中提到】
: 我是说如果我不会lisp。。。
: ml也可以写的很简洁,但是初学者可能看不懂
: let rec IsMonoInc = function
: | [] -> true
: | [f] -> true
: | f::((s::_)as remain) -> if f >= s then false else IsMonoInc(remain)

avatar
p*2
27

大牛会多少种fp语言呀?

【在 G***l 的大作中提到】
: 我是说如果我不会lisp。。。
: ml也可以写的很简洁,但是初学者可能看不懂
: let rec IsMonoInc = function
: | [] -> true
: | [f] -> true
: | f::((s::_)as remain) -> if f >= s then false else IsMonoInc(remain)

avatar
G*l
28
不是大牛。scheme会一些。haskell学了一点后来没有空学了。现在用的最多的是F#,
因为是.net上的。.net上没有支持比较好的lisp family的。不过有的话我可能也不太
会用,虽然理解,但是欣赏不了括号。。。。

【在 p*****2 的大作中提到】
:
: 大牛会多少种fp语言呀?

avatar
H*S
29
1. fun (xs) = case xs of
[] => true
| x::[] => true
| x::y::xs' => if (x <= y) fun (y::xs') else false
2. fun addOneToAll(x, L) = case L of
[] => []
| y::ys => (x::y) :: (addOneToAll (x, ys))
Most amazing thing about ML is although everything is static typed, you don'
t need to specify which class/type the input argument is and return value is
-- type inference will all handle that for you :-)
BTW Dan Grossman recently opened a course "Programming Language" in coursera
. If you are interested in learning ML, I would suggest going there.

[1

【在 k***t 的大作中提到】
: Write a function increasing: int list -> bool that returns true if its
: input is a list of integers in increasing order.
: Define function addOneToAll(x, L) that takes a value
: x and add it to all the elements in L, which is a list of lists.
: For example, addOneToAll(1, [nil, [2], [3], [2,3]]) = [[1], [1,2], [1,3], [1
: ,2,3]].
: 才开始学编程,这两个怎么写啊?
: 第二个题,我写了这样的可是不工作:
: -fun addOneToAll(a,nil)=nil
: |fun addOneToAll(a,[x]::[y]::nil)=(a::[x])::addOneToAll(a,[y]::nil)::nil;

avatar
c*C
30
第一题
fun increasing(lst: int list) =
case lst of
[] => true
| i::[] => true
| i::(j::lst') => i < j andalso increasing(lst')
第二题
fun addOneToAll思路跟第一题相似

[1

【在 k***t 的大作中提到】
: Write a function increasing: int list -> bool that returns true if its
: input is a list of integers in increasing order.
: Define function addOneToAll(x, L) that takes a value
: x and add it to all the elements in L, which is a list of lists.
: For example, addOneToAll(1, [nil, [2], [3], [2,3]]) = [[1], [1,2], [1,3], [1
: ,2,3]].
: 才开始学编程,这两个怎么写啊?
: 第二个题,我写了这样的可是不工作:
: -fun addOneToAll(a,nil)=nil
: |fun addOneToAll(a,[x]::[y]::nil)=(a::[x])::addOneToAll(a,[y]::nil)::nil;

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。