moduleFstarList(* Don't use Fstar as module name *)(* If used in type refinements, you must specify return effects, Ex: "Tot".
But always use the most precise type as it possible *)vallength:xs:list'a->Tot(r:int{r>=0})letreclengthxs=matchxswith|[]->0|x::xs->1+lengthxs(* Only two branches in pattern matching are needed. _,[] and [],_
are not neccesary *)valzip:xs:list'a->ys:list'b{lengthxs=lengthys}->Tot(r:list('a*'b){lengthr=lengthxs&&lengthr=lengthys})letreczipxsys=matchxs,yswith|[],[]->[]|x::xs,y::ys->(x,y)::zipxsys
letreczipxsys=(xs,ys)|>function|[],[]->[]|_____,[]->failwith"xs and ys aren't of same length"|[],_____->failwith"xs and ys aren't of same length"|x::xs,y::ys->(x,y)::zipxsys(* Note: | _____,[ ] | [ ],_____ -> failwith "..." isn't supported *)letr=zip[1..10]['a'..'z']
F# Code output:
>
System.Exception: xs and ys aren't of same length
at Microsoft.FSharp.Core.Operators.FailWith[T](String message)
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at FSI_0004.zip[a,b](FSharpList`1 xs, FSharpList`1 ys) in C:\tmp\zip.fsx:line 5
at <StartupCode$FSI_0005>.$FSI_0005.main@() in C:\tmp\zip.fsx:line 9
Stopped due to error