prosyslab-classroom / cs348-information-security

61 stars 10 forks source link

[Question][Hw2][Ocaml] Is there a way to assert list length? #250

Closed m-spitfire closed 1 year ago

m-spitfire commented 1 year ago

Name: Murad Bashirov

Hello. Is there a way to assert the list length, so when I pattern match it, so it doesn't give me the warning "pattern-matching is not exhaustive". I have tried

let () = assert (List.length l = 4)

But it doesn't get rid of the warning.

bonjune commented 1 year ago
match fancy_list with
| x1 :: x2 :: x3 :: x4 :: [] -> do_something_useful
| _ -> failwith "the length of list must be 4"
m-spitfire commented 1 year ago

Oh, I was doing that and returning x1;x2;x3;x4 list from match, then matching again as value of match expression, then I realized I can return a tuple and pattern match on that. Thanks for giving me insight!