{"id":108,"date":"2008-03-25T03:17:51","date_gmt":"2008-03-25T08:17:51","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=108"},"modified":"2008-03-25T04:53:51","modified_gmt":"2008-03-25T09:53:51","slug":"lists-in-f","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/","title":{"rendered":"Lists in F#"},"content":{"rendered":"<p>In this post I will talk about the lists in F#, one of the fundamental concepts of the language. What should be said from the very beginning is that list are imutable single linked list. That means whenever you change a list, a new list is created.<\/p>\n<p>You can declare a list in the following ways:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet list1 = [1;2;3;4]<br \/>\nlet list2 = 5::6::7::8::[]<br \/>\n<\/PRE><\/p>\n<p>To print the content of the list you can do this:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nprintfn &#8220;list1: %a&#8221; output_any list1<br \/>\nprintfn &#8220;list2: %a&#8221; output_any list2<br \/>\n<\/PRE><\/p>\n<pre class=\"console\">\r\nlist1: [1; 2; 3; 4]\r\nlist2: [5; 6; 7; 8]\r\n<\/PRE>\r\n<p>You can concatenate two lists with operator @:<\/p>\r\n<PRE class=\"prettyprint\">\r\nlet list3 = list1 @ list2\r\nprintfn \"list3: %a\" output_any list3\r\n<\/PRE>\r\n<pre class=\"console\">\r\nlist3: [1; 2; 3; 4; 5; 6; 7; 8]\r\n<\/pre>\n<p>and you can append elements to the beginning of the list with operator ::<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet list4 = -1::0::list3<br \/>\nprintfn \"list4: %a\" output_any list4<br \/>\n<\/PRE><\/p>\n<pre class=\"console\">\r\nlist4: [-1; 0; 1; 2; 3; 4; 5; 6; 7; 8]\r\n<\/pre>\n<p>You can also use the List (defined in Microsoft.FSharp.Code) functionality to print a list by iterating over its elements:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlist3: [1; 2; 3; 4; 5; 6; 7; 8]<br \/>\n<\/PRE><br \/>\n<PRE class=\"console\"><br \/>\n1 2 3 4<br \/>\n<\/PRE><\/p>\n<p>The same can be achieved using the pipe operator:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlist1 |> List.iter (fun x -> printf \"%d \" x)<br \/>\n<\/PRE><\/p>\n<p>You can also iterate and get the index of the list elements, with List.iteri:<\/p>\n<pre class=\"prettyprint\">\r\nlist1 |> List.iteri (fun i x -> printfn \"list1[%d] : %d \" i x)\r\n<\/PRE>\r\n<PRE class=\"console\">\r\nlist1[0] : 1\r\nlist1[1] : 2\r\nlist1[2] : 3\r\nlist1[3] : 4\r\n<\/PRE>\r\n\r\n<p>List have a special representation, a head followed by a tail, that is in turn another list (including empty list []). Let's consider the list [1;2;3]. It has the head 1, and the tail [2;3]. The tail, in turn, has the head 2 and the tail [3]. This tail has the head 3 and the tail [], which is the empty list.\r\nYou can see the head and tail of a list with List.hd and List.td:<\/p>\r\n<PRE class=\"prettyprint\">\r\nprintfn \"head list1: %a\" output_any (List.hd list1)\r\nprintfn \"tail list1: %a\" output_any (List.tl list1)\r\n<\/PRE>\r\n<p>The ouput for list1 [1;2;3] is:<\/p>\r\n<pre class=\"console\">\r\nhead list1: 1\r\ntail list1: [2;3]\r\n<\/pre>\n<p>Enough with basic things. Let's try working with lists.<\/p>\n<h3>1. Minimum and maximum from a list<\/h3>\n<p>We can compute the maximum (or minimum) of a list using the following algorithm:<\/p>\n<ul>\n<li>if the list is empty, indicate error<\/li>\n<li>if the list has only one element, that is the maximum (or minimum)<\/li>\n<li>if the list has at least to elements, compute the maximum between that element and the maximum from the rest of the list<\/li>\n<\/ul>\n<p>That sounds like a recursive operation, which can be simply put in F# like this:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet rec greatest_element l =<br \/>\n    match l with<br \/>\n    | [] -> failwith \"empty list\"<br \/>\n    | [x] -> x<br \/>\n    | x::rest -> max x (greatest_element rest)<\/p>\n<p>let rec smallest_element l =<br \/>\n    match l with<br \/>\n    | [] -> failwith \"empty list\"<br \/>\n    | [x] -> x<br \/>\n    | x::rest -> min x (smallest_element rest)<br \/>\n<\/PRE><\/p>\n<p>We can use that like this:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet list1 = [1;2;3;4;-4;-3;-2;-1]<br \/>\nlet list2 = []   <\/p>\n<p>try<br \/>\n   printfn \"maximum from list1: %d\" (greatest_element list1)<br \/>\n   printfn \"minimum from list1: %d\" (smallest_element list1)<\/p>\n<p>   printfn \"maximum from list2: %d\" (greatest_element list2)<br \/>\n   printfn \"minimum from list2: %d\" (smallest_element list2)<br \/>\nwith<br \/>\n   Failure msg -><br \/>\n      printfn \"Error: %s\" msg<br \/>\n<\/PRE><\/p>\n<p>and the output would be:<\/p>\n<pre class=\"console\">\nmaximum from list1: 4<br \/>\nminimum from list1: -4<br \/>\nError: empty list<br \/>\n<\/PRE><\/p>\n<h3>2. Reversing a list<\/h3>\n<p>How would we reverse a list? We should take the last element and append to it the one before the last. To the new list we append the one before the one before the end, etc. That again sounds recursive.<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet rec revert_list l =<br \/>\n   match l with<br \/>\n   | [] -> []<br \/>\n   | x::rest -> (revert_list rest) @ [x]<\/p>\n<p>let list1 = [1;2;3;4;-4;-3;-2;-1]<\/p>\n<p>printfn \"list1: %a\" output_any list1<br \/>\nprintfn \"list2: %a\" output_any (revert_list list1)<br \/>\n<\/PRE><\/p>\n<p>And here is the output:<\/p>\n<p><PRE class=\"console\"><br \/>\nlist1: [1; 2; 3; 4; -4; -3; -2; -1]<br \/>\nlist2: [-1; -2; -3; -4; 4; 3; 2; 1]<br \/>\n<\/PRE><\/p>\n<h3>3. Inserting in a list<\/h3>\n<p>So how could we insert an element in a list, before or after a specified element? We can use the following algorithm:<\/p>\n<ul>\n<li>if the list is empty, the new list has one element (the one to insert)<\/li>\n<li>else, if the head is the element we are looking for, create a list, with the new element either before the head, or between the head and the tail<\/li>\n<li>else, if the head is not the element we are looking for, append the head to a list created by inserting the new element in the tail.<\/li>\n<\/ul>\n<p>You got that right, recursion again.<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet rec insert_after elem newelem l =<br \/>\n    match l with<br \/>\n    | [] -> [newelem]<br \/>\n    | x::rest -> if x = elem then<br \/>\n                    (x::newelem::rest)<br \/>\n                 else<br \/>\n                     x::(insert_after elem newelem rest)<\/p>\n<p>let rec insert_before elem newelem l =<br \/>\n    match l with<br \/>\n    | [] -> [newelem]<br \/>\n    | x::rest -> if x = elem then<br \/>\n                    (newelem::x::rest)<br \/>\n                 else<br \/>\n                    x::(insert_before elem newelem rest)        <\/p>\n<p>let list1 = [1;2;3;4;-4;-3;-2;-1]<br \/>\nlet list2 = insert_after 4 6 list1<br \/>\nlet list3 = insert_before 6 5 list2<\/p>\n<p>printfn \"list1: %a\" output_any list1<br \/>\nprintfn \"list2: %a\" output_any list2<br \/>\nprintfn \"list3: %a\" output_any list3<br \/>\n<\/PRE><\/p>\n<p>And the output is:<\/p>\n<pre class=\"console\">\nlist1: [1; 2; 3; 4; -4; -3; -2; -1]<br \/>\nlist2: [1; 2; 3; 4; 6; -4; -3; -2; -1]<br \/>\nlist3: [1; 2; 3; 4; 5; 6; -4; -3; -2; -1]<br \/>\n<\/PRE><\/p>\n<h3>4. Removing elements from a list<\/h3>\n<p>As a last exercise, let's consider the removing of elements from a list. The following steps can be used to remove elements:<\/p>\n<ul>\n<li>if the list is empty, return an empty list<\/li>\n<li>if the list is not empty and the head meets the removing criteria, return a list obtained by reiterating the algorithm on the tail of the list<\/li>\n<li>if the list is not empty and the head does not meet the removing criteria, return a list obtained by appending the head to a list optained by reiterating the algorithm on the tail of the list<\/li>\n<\/ul>\n<p><PRE class=\"prettyprint\"><br \/>\nlet rec remove_if l predicate =<br \/>\n    match l with<br \/>\n    | [] -> []<br \/>\n    | x::rest -> if predicate(x) then<br \/>\n                    (remove_if rest predicate)<br \/>\n                 else<br \/>\n                     x::(remove_if rest predicate)<br \/>\n<\/PRE><\/p>\n<p>The great thing about this implementation is that we can pass a lambda expression as a predicate, and use it to specify the criteria for removing elements. We can remove like that, for instance, the odd elements, or the even elements, or the negative elements. Here is some sample code:<\/p>\n<p><PRE class=\"prettyprint\"><br \/>\nlet list1 = [1;2;3;4;-4;-3;-2;-1]<\/p>\n<p>let list2 = remove_if list1 (fun x -> (abs x &&&1) = 1)<br \/>\nlet list3 = remove_if list1 (fun x -> (abs x &&&1) = 0)<br \/>\nlet list4 = remove_if list1 (fun x -> x < 0)\n\nprintfn \"%a\" output_any list1\nprintfn \"%a\" output_any list2\nprintfn \"%a\" output_any list3\nprintfn \"%a\" output_any list4\n<\/PRE><\/p>\n<p>The output for this sample is:<\/p>\n<p><PRE class=\"console\"><br \/>\n[1; 2; 3; 4; -4; -3; -2; -1]<br \/>\n[2; 4; -4; -2]<br \/>\n[1; 3; -3; -1]<br \/>\n[1; 2; 3; 4]<br \/>\n<\/PRE><\/p>\n<p>I hope this will help you to get a grip on how you can work on lists in F#.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will talk about the lists in F#, one of the fundamental concepts of the language. What should be said from the very beginning is that list are imutable single linked list. That means whenever you change a list, a new list is created. You can declare a list in the following &#8230; <a title=\"Lists in F#\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/\" aria-label=\"Read more about Lists in F#\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[37,38],"tags":[39],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-fsharp","category-tutorials","tag-f-tutorial-article-list-recursive"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"f# tutorial article list recursive\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Lists in F#\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-03-25T08:17:51+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2008-03-25T09:53:51+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Lists in F#\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#article\",\"name\":\"Lists in F#\",\"headline\":\"Lists in F#\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2008-03-25T03:17:51+02:00\",\"dateModified\":\"2008-03-25T04:53:51+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#webpage\"},\"articleSection\":\"F#, Tutorials, F# tutorial article list recursive\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"position\":4,\"name\":\".NET\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/#listItem\",\"name\":\"F#\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/#listItem\",\"position\":5,\"name\":\"F#\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#listItem\",\"name\":\"Lists in F#\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#listItem\",\"position\":6,\"name\":\"Lists in F#\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/#listItem\",\"name\":\"F#\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/\",\"name\":\"Lists in F#\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/03\\\/25\\\/lists-in-f\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2008-03-25T03:17:51+02:00\",\"dateModified\":\"2008-03-25T04:53:51+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Lists in F#","description":"","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/","robots":"max-image-preview:large","keywords":"f# tutorial article list recursive","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#article","name":"Lists in F#","headline":"Lists in F#","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2008-03-25T03:17:51+02:00","dateModified":"2008-03-25T04:53:51+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#webpage"},"articleSection":"F#, Tutorials, F# tutorial article list recursive"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","position":4,"name":".NET","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/#listItem","name":"F#"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/#listItem","position":5,"name":"F#","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#listItem","name":"Lists in F#"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#listItem","position":6,"name":"Lists in F#","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/#listItem","name":"F#"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/","name":"Lists in F#","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2008-03-25T03:17:51+02:00","dateModified":"2008-03-25T04:53:51+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Lists in F#","og:url":"https:\/\/mariusbancila.ro\/blog\/2008\/03\/25\/lists-in-f\/","article:published_time":"2008-03-25T08:17:51+00:00","article:modified_time":"2008-03-25T09:53:51+00:00","twitter:card":"summary","twitter:title":"Lists in F#"},"aioseo_meta_data":{"post_id":"108","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:13:02","updated":"2025-12-12 07:18:10","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"In this post I will talk about the lists in F#, one of the fundamental concepts of the language. What should be said from the very beginning is that list are imutable single linked list. That means whenever you change a list, a new list is created. You can declare a list in the following&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/\" class=\"advgb-post-tax-term\">F#<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/articles_and_tutorials\/tutorials\/\" class=\"advgb-post-tax-term\">Tutorials<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">F#<\/span>","<span class=\"advgb-post-tax-term\">Tutorials<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/articles_and_tutorials\/tutorials\/\" class=\"advgb-post-tax-term\">F# tutorial article list recursive<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">F# tutorial article list recursive<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 19 years ago","modified":"Updated 19 years ago"},"absolute_dates":{"created":"Posted on March 25, 2008","modified":"Updated on March 25, 2008"},"absolute_dates_time":{"created":"Posted on March 25, 2008 3:17 am","modified":"Updated on March 25, 2008 4:53 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-1K","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":0,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}