functional programming - How to access a value in type from a list -


this structure of project

type a{ t1; t2; }  , b = var of , c = b list type d = c list 

now have function d parameter. need assign t2 unique value every time call function.

i guess can't assign value directly t2, instead need return new type new value of t2. think that's how functional language work

my problem here don't know how access value using function

i still learning syntax, if can give me example, great

your question isn't clear @ all.

if want a record can change 1 fields, can use keyword mutable. if have type = { t1 : int ; mutable t2 : int }, if x value of type a, can use syntax x.t2 <- 9 instance.

if understand correctly, want be:

type = { t1 : int ; mutable t2 : int } type b = var of type c = b list type d = c list  let func d =   list.iter (fun c -> list.iter (function (var a) -> a.t2 <- a.t2 + 1) c) d 

which can rewritten (by eta-conversions)

let func = list.iter (list.iter (function (var a) -> a.t2 <- a.t2 + 1)) 

this function iterate on each c in d = c list , each of them iterate b var a modifies t2.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -