2016-03-17 14 views
0

由於我是Ocaml的新成員,並且我沒有找到資源,所以我需要您的幫助來解決這個問題功能!我想通過將int轉換爲char來生成一個數字列表。在'a'中變換0,在'b'中變爲1,在'c'中變換2等等...在OCaml中

module Util = 
sig 
(* transform 0 in ’a’, 1 in ’b’, 2 in ’c’ etc... *) 
val int_to_char : int -> char 
(*gen_random_list long max *) 
(* generate a list of positive numbers <= max *) 
(* the length of the list is long *) 
val gen_random_list : int -> int -> int list 
end 
+0

你說你沒有找到資源,但你甚至嘗試過ocaml.org嗎?如果是這樣,是缺乏的東西? –

回答

0

有很好的資源,在ocaml的http://ocaml.org

下面是轉換1 'a' 和2至 'B' 的功能。但我會說你需要更仔細的說明,但有三個例子沒有回答你的問題。

let ntoc x = Char.chr (x + Char.code 'a' - 1) 

閱讀有關在OCaml的手冊CharRandom模塊。

+0

謝謝!你是對的。但你能告訴我怎樣才能隨機生成一個正數列表? – Ronald

+0

這看起來像一個學校作業。你應該閱讀關於隨機模塊,然後編寫你自己的代碼。如果它不起作用,請在此處顯示代碼並解釋哪些工作不正確。沒有人會贏,如果SO爲你做功課:-) –

相關問題