我想實現一個使用標準ML的CML擴展的併發列表,但我遇到了可能與我是一個標準ML中的新手做的錯誤。我將clist實現爲具有輸入和輸出通道,並將列表狀態存儲在一個循環中。但是我的代碼無法編譯,並給出以下 structure Clist : CLIST =
struct
open CML
datatype 'a request = CONS of 'a | HEAD
嗨,我需要幫助理解爲什麼我在這段代碼中得到一個值限制錯誤,以及如果可能的話我怎樣才能解決它。 特別是在val cnil中,我試圖創建一個空的CLIST結構來匹配簽名,但我一直得到這個值限制錯誤。 感謝您的幫助 structure Clist : CLIST =
struct
open CML
datatype 'a request = CONS of 'a | HEAD
datatype inttree = Empty | Node of int * inttree * inttree
fun insert(t,i)= if t=Empty then Node(i,Empty,Empty)
else if t=Node(j,l,r):
if (i=j)
then t
else if (i < j)
t
我相信我在將我的第一個函數轉換爲僅使用賦值和循環方面處於正確的軌道。我知道這是針對函數式編程,但這正是教授想要的。 遞歸函數: fun sub (x, y, []) = []
| sub (x, y, z::zz) = if x = z then y::sub(x, y, zz)
else z::sub(x, y, zz);
迭代翻譯: fun sub2 (x, y,
我寫了一個ml函數,並在輸出中獲得 out = Mary(「a」,[Zary#,Zary#]) 其中Mary和Zary是構造函數。但正如你所看到的,輸出中有一些「#」。 if if val Mary(「a」,x)= out; 然後它顯示 x = [Zary(「b」),Zary(「c」)];哪個是對的。 我想獲得完整的輸出而不是散列。請幫助我。