F # Learning Notes (list)

Source: Internet
Author: User

list, the list in F # is also recursive, and the recursive structure makes the syntax clearer and easier to understand

[<entrypoint>]let main argv=Let list1= [1;3;5] List1|> PRINTFN"%A"Let list2= [2..2..Ten] List2|> PRINTFN"%A"Let list3= [ forIinch 1..4i*i*i] list3|> PRINTFN"%A"Let x= List1. [0] PRINTFN"%i"x Let Len1,len2=List1. Length,list2. Length PRINTFN"%i,%i"len1 len2 let el=[] (el. Length=0) |> PRINTFN"%b"Let b= ([1;3;5] <> [5;3;1]) b|> PRINTFN"%b"    //List1. [1] <-7//the list element is immutable, here Hi errorLet List4 =list.append list1 list2 list4|> PRINTFN"%A"Let list44=list1 @ list2 list44|> PRINTFN"%A"Let list5= List1 @ [8;Ten] @ list3 list5|> PRINTFN"%A"Let sL1= ["Beijing";"Jinan";"Shanghai";"Hangzhou";"Wenzhou";"Fuzhou"] Let start=Sl1.head let Routel=Sl1.tail Start|> PRINTFN"%s"Let AL= [1] PRINTFN"Head:%O, Tail:%O"al.head al.tail Let sL2="Tianjin":: Routel let SL3= Start:: ["Nanchang";"Fuzhou"] SL2|> PRINTFN"%A"sL3|> PRINTFN"%A"Let sL4="Xian"::"Zhengzhou":: Sl3.tail sL4|> PRINTFN"%A"Let htt L1=match L1 with| [] []        | [_]L1| Head:: Tail(tail @ [head]) (HTT [1..5]) |> PRINTFN"%A"(htt [ -]) |> PRINTFN"%A"Let rec CAs (L1:stringlist) =match L1 with| []""| [_]L1. Head| Head:: Tail, head +" "+(CAS tail) (CAS ["Beijing";"Haidian";"Zhongguancun"]) |> PRINTFN"%A"Let rec match2 L1 a b=match L1 with| [] | [_]false| X:: Y:: Tail (x=a && y=b) | | (Y=a && tail <> [] && tail. HEAD=B) | |(MATCH2 tail a B) (Match2 [1..5]1 2) |> PRINTFN"%b"PRINTFN"%b,%b"(Match2 [1..5]2 4) (Match2 [1..5]4 5) Let TpL1= List.zip [2..8] [ forIinch 2..8(floati) * * (10.0-floati)] tpL1|> PRINTFN"%A"Let _, fL1=list.unzip tpL1 fL1|> PRINTFN"%A"Let y=List.max fL1, List.min fL1, list.average fL1 y|> PRINTFN"%A"Let fL2=List.rev fL1 fL2|> PRINTFN"%A"Let fArr1=array.oflist fL1 fArr1|> PRINTFN"%A"Let fArr2= Array.tolist (Array.sub fArr10 4) FARR2|> PRINTFN"%A"    0 //returns an integer exit code

There's nothing really different from Scala.

Advanced list:

[<entrypoint>]let main argv=Let hL1= [[1;2;3;5]; [8; -; +]; [ the; -]] hL1. [0] |> PRINTFN"%A"Let x1= HL1. [1]. [1] Let iArr1=List.toarray hL1 iArr1|> PRINTFN"%A"Let Lltoarr (L1:intList List) =Let arr= Array.create L1. Length [|0|]         forIinch 0.. L1. length-1  DoArr.[i]<-List.toarray L1. [i] arr let iArr2= Lltoarr [[1;2;3;5]; [8; -; +]; [ the; -]]    0 //returns an integer exit code

I've been doing the rest of the day, studying here.

F # Learning Notes (list)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.