<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6810762626202656454</id><updated>2024-11-01T12:13:00.416+01:00</updated><category term="F#"/><category term="dotnetmag"/><category term="Open XML"/><category term="WinRT"/><category term="Monad"/><category term="Windows 8 Store App"/><category term="C#"/><category term="Word"/><category term="Data Binding"/><category term="LINQ"/><category term="MVVM"/><category term="XDocument"/><category term="portable libraries"/><category term="spreadsheet"/><category term="Collection"/><category term="Legacy"/><category term="Metro"/><category term="NuGet"/><category term="Script"/><category term="async/await"/><category term="discriminated unions"/><category term="oData"/><category term="tweet2word"/><category term="union type"/><title type='text'>PsAccelerator</title><subtitle type='html'>Blog by Piet Amersfoort of &lt;a href=&quot;http://psaccelerator.nl/&quot;&gt;PsAccelerator.nl&lt;/a&gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>36</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-7312279529515493835</id><published>2014-06-23T21:07:00.001+02:00</published><updated>2014-06-23T21:07:32.601+02:00</updated><title type='text'>Creating real world WPF applications with Prism 5 and F# (part 2 - MEF)</title><content type='html'>&lt;p&gt;In the &lt;a href=&quot;http://ps-a.blogspot.com/2014/06/creating-real-world-wpf-applications.html&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt; I explained how you could port the Hello World example from the Quick Starts of Prism 5. There was one issue. The Shell had knowledge op the module. This could be solved in different ways, for instance with configuration files.&lt;/p&gt; &lt;p&gt;I prefer a pluggable solution. Just by dropping dlls into a directory and everything should work fine. Microsoft has a framework that supports this way of working: &lt;a title=&quot;http://msdn.microsoft.com/en-us/library/dd460648(v=vs.110).aspx&quot; href=&quot;http://msdn.microsoft.com/en-us/library/dd460648(v=vs.110).aspx&quot; target=&quot;_blank&quot;&gt;Managed Extensibility Framework (MEF)&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;In this post I will show you how you can move the Hello World example from Unity to MEF.&lt;/p&gt; &lt;p&gt;I start from scratch and highlight the MEF changes You could also rework the Unity solution.&lt;/p&gt; &lt;p&gt;Create a empty solution, and add a project called Shell.&lt;/p&gt; &lt;p&gt;Next add:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;FsXaml in case you don’t want to use the Xaml Type provider&lt;/li&gt; &lt;ul&gt;&lt;!--EndFragment--&gt;&lt;/ul&gt; &lt;li&gt;Prism&lt;/li&gt; &lt;li&gt;the Prism.MEFExtensions.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWyxMqoJBv6RUmMh0IBvGmX78KQaHpj2peLTQgBjTKER5n0t2mxd2otG4nfbgNicUr7nhcaFBYO0QT_rQalmoJy6L969_1xhQcCX2-HOyS8nFmvY4ugmzJvXyL77atwa84ZHDsRUwYldRT/s1600-h/image3.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5heBh1Wa3wOG1PWPv8VtXcts1UcjWVbsZvuGk1Q3iQAk1668an68UTRwqxhrUE12z9pHV0BZ8Y_AmTGe9FlMAHMe_d3mfLVajO7UvwAoc168rCwbuCUQiPzCC0-hcYuB9C6aYBP-fszU0/?imgmax=800&quot; width=&quot;440&quot; height=&quot;106&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;If needed add the required references&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzJWeQjM3HFZ9I5xFmulhk_p8Imho_P6cjMP9wBDXAayDC2wZYQacDO0RWmTbNr3cGkeormfMUWB0xvtDKSm-AbnLO2N6NDIp5Q8NhkH4N0oAxu9p-7sevQ9B87IQXd7cWAEvflm-vDVI7/s1600-h/image%25255B8%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMbWZY57q5oe_APCWLsbrgvuk_HCAepYU9h8_HfU2hwsi4en-1UarjxHgRKpzILE1uoRLIVDEFqVytfL45HfJ2WCouoo2YsEj-d9ISwGXBctfDTpV-tvEKcQVyJk-HK3ET8XynURxA6onH/?imgmax=800&quot; width=&quot;235&quot; height=&quot;405&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In this case we added also System.ComponentModel.Components to get access to MEF.&lt;/p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYBvrc0gOx2XTPWIqNMhMSuSzue6YH1iSr5SjgpNZ_B1VWsWbPHIHqmP-BsvkQu1hAS_a9hM6toem1EjfQACAGIPUx5rPa21lEOtRJheF5BQfG1ksU_X11fnibJVyKaeFW2nBvLLBdcCQ5/s1600-h/image4%25255B1%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2agmn-76kxKlIM5-ZracLfdTHh8Ta8vIXrIhLSXALeYqMHhc6SlWsvuXzU9u86ifhkv_Hq_UyaZ0Rm4kFI3LKIrX5Z511VFrE85eT5rcPdqSxi7JCgSppafnJmj7BZpYTP5bjF7SfOV5o/?imgmax=800&quot; width=&quot;463&quot; height=&quot;71&quot;&gt;&lt;/a&gt; &lt;p&gt;Make sure it is a Windows application:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqB5dkXg1EyrmLPxf_LoydqUl7OY0OQTbIDeJLfNKyVAML6HG2Lyprm12ruRTnhcxazxjz-S4YrWIlU8FnQxZE-oqWb0D1Z2kr8kMeIko7QZpls4EAXTPFmpCP3PsPftbPD0NO5Q_u9npC/s1600-h/image%25255B16%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsEO1gHn4jujYrM5iIST-apuq9hsFYnFNOJR5YMKvynybnbdsQWCGaGWHlEShG-Yld2YKXMWkRsPZIR7pvFkqInyFanGDxkQsjmn_K5u5IzHQekdmqtOmIK00fdarl_xoBLK4yq3RbfmhZ/?imgmax=800&quot; width=&quot;525&quot; height=&quot;136&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Next remove, add or rename the files &lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihGVhl_IwJPp3abTK2ywWDSNmu3WYka5_JzA4YUEiikRkCRk4AghyBagtX9yNhPJ7s1OpQUcNEM8POlMfmsN8QFGx6nX4jSaGziGnnGbiLBLrkieYfrN8nYmd-tH07Cia9-sR058KXDk2d/s1600-h/image%25255B20%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrfMm7jRo1Yue7yVwsTEpb8xFn_YUgir8dVfGo9bEADmVYU4eSKSwV-ooSuhF1OsiId7Gn-9IYCphkOP-qJIc9B4PfwwTOWgOXoTZ2kMvdigaAxBUTgR9fgSPkWch0dGAwtI6jaKBmpABY/?imgmax=800&quot; width=&quot;355&quot; height=&quot;261&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;and be sure the xaml file has Resource as build action and contains the following content.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Window &lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;cal&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://www.codeplex.com/prism&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Title&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Hello World&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;300&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;300&quot;&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ItemsControl &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;MainRegion&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;cal&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;RegionManager.RegionName&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;MainRegion&quot; /&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Window&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;We have done all the preparation. So we add the app class and the boodstrapper to the App.fs file.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MainApp&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.IO&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.ComponentModel.Composition&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.ComponentModel.Composition.Hosting&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows.Controls&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Modularity&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.MefExtensions&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FsXaml&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Shell = XAML&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;Shell.xaml&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;App() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Application()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.OnStartup(e) =&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.OnStartup(e)&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;bootstrapper = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Bootstrapper() &lt;br /&gt;            bootstrapper.Run()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Bootstrapper() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MefBootstrapper()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.CreateShell() = &lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;window = Shell()&lt;br /&gt;            window.CreateRoot() :&amp;gt; DependencyObject&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.InitializeShell() =&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.InitializeShell()&lt;br /&gt;            App.Current.MainWindow &amp;lt;- x.Shell :?&amp;gt; Window&lt;br /&gt;            App.Current.MainWindow.Show()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ConfigureAggregateCatalog() =&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;path = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;@&quot;..\..\..\DirectoryModules&quot;&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;dir = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DirectoryInfo(path);&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;not dir.Exists &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;then &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;dir.Create()&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;catalog = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DirectoryCatalog(path)&lt;br /&gt;            x.AggregateCatalog.Catalogs.Add(catalog)&lt;br /&gt;&lt;br /&gt;[&amp;lt;STAThread&amp;gt;]&lt;br /&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;App()).Run()|&amp;gt; ignore&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Let’s compare this with Unity file from the previous post. First I have added or renamed some namespaces.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The app class did not change.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The bootstrapper now derives from &lt;span style=&quot;background: white; color: black&quot;&gt;MefBootstrapper. In this case we override the ConfigureAggregegateCatalog. We add a DirectoryModules directory in case it did not exists. This will prevent the creation of an exception by the DirectoryCatalog in case the directory id not exist. Next we add the catalog to the AggegateCatalog. Mef and Prism are now able to handle dll’s that are put into DirectoryModules directory.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;F5 and everything works fine&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4X2IUF6Cf7q2d3T8xbCgmq0Lkh5zajzaoWywPAtf9Q15cVCyDjhjFLG7DTZi2MBypU6JmjvDe57iMvLACcawSLaFIsg5Y2CRoob2xDtcLU1SVgzglHd-YfO_HHzHPBDaGZC6sU9uiEOTy/s1600-h/image%25255B24%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_2khkNXqzaexpSeJgZAxd6x5eQ77wOL5XExVt6iY3zm_pxflAxSOzgYKo-7LofIFVw-L3NwC0rc4Wfax_OXuoEpdL5mxgxp-fzB0JI3lWugQeDUFKneYyrtXAJnGK0PSDm2sVBC2uVLqm/?imgmax=800&quot; width=&quot;381&quot; height=&quot;339&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;and we have created the directory.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw6y6Px_GUDlIj71_S7l2o3Mk7YDzKsp5sAz9G9Vv7ZqddvfT8giBdszNIqmlt8opmdyRcI-b_QWi4RPYhkxNWsbxzNl0lkBfSt-eUWkQOwjtuyWAYar54JcT6zFedyL6GIOEieqoY0dck/s1600-h/image%25255B51%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHdFuHeYv_l2pgvln0o5wqMlsBgAjV9N-7v4c2R7-0fO1yiJrDk57gEYm_aTHnw353WO9EIV95FaVFB-WrGbVzzxfR_VlLC9RA6UImEjufrsXEOOTkeCfUCBeyCktQ9SGTwNSKqRb5Oidh/?imgmax=800&quot; width=&quot;344&quot; height=&quot;88&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Next we create the Hello World Module again by taking the same steps as we did with the Shell. &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Except this time we create a dll.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHeQuaIj0vw1L0FulhiemdX_KCMNuNyiXQMaQsLzt-1C-I3UqT7L0QDFvXU8WFMkTbvtpSntAHwME5Xt9Ngl1XujVtVyebKWMdCi0Yl_mTcc0i9M0OD77Dn1J9etJdEoTR7j5lUhLzSv5G/s1600-h/image%25255B28%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG05kzv1g9tcll4R2TM8AXz6t_1CrSfizGP-E0riJvdwfqWI6ZgovhirHTzFbU0EIPtryZUnb9jL1oWaqh3qrqPONSUEm100fIW9V66PbCzfR__aN4Ij5ruC8ZbZvhAyu2k7XWDMQLMx40/?imgmax=800&quot; width=&quot;500&quot; height=&quot;109&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;The xaml of the HelloWorldView is the same as in the Unity example:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;UserControl&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br /&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Hello World&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Green&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Calibri&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;24&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontWeight&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Bold&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br /&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;UserControl&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Next step is to create the module:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldModule&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows.Controls&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.ComponentModel.Composition&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Modularity&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Regions&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Mvvm&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.MefExtensions.Modularity&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FsXaml&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldXaml = XAML&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;HelloWorldView.xaml&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;[&amp;lt;ModuleExport(typeof&amp;lt;HelloWorldModule&amp;gt;)&amp;gt;]&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldModule =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;val &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;regionViewRegistry: IRegionViewRegistry&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;IModule &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with&lt;br /&gt;        member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Initialize() = x.regionViewRegistry.RegisterViewWithRegion(&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;MainRegion&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldXaml():&amp;gt; obj)&lt;br /&gt;    [&amp;lt;ImportingConstructor&amp;gt;]&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;(regionViewRegistry) = {regionViewRegistry = regionViewRegistry}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Some of the namespaces were renamed or added. &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;This time we need to handle the MEF requirements. We need to add attributes. The class has the ModuleExport attribute. This attribute is provided by Prism:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOxef8LE9kKGxYauOG8uLzZ9FNRlVN-jP3Jvc2oecit_R8iaVzekcBWm-yKGV4aFpWzqFapy6BVnOybBOlw23rjlHe630YLs2ybUTXe7usbBC1-9mKab3fQIvV0lMR1l2cUnDoiMA_NoO7/s1600-h/image%25255B32%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHEghCfwBWLXNpB9MYSOgHTjktWiRCh1MduRsCjkXZP1wJT4j_iqauUFYgxrIrR-XDAU64izcrsZVhPnHb1dbI5_Cqdb-Ce-CyEmokBhi2AFQ5oP5H5n-fryg6sCYUyBwT4loDskvrjGqP/?imgmax=800&quot; width=&quot;560&quot; height=&quot;159&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;and take care of the registration of the module. &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;This time we can’t use the default constructor because we need to add the ImportingConstructor attribute to the constructor. &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;There is no way in F# to add an attribute to the primary constructor.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyehJE8alRDsc1xPaLPP0kbXLC2Beysx0PYwpkpWv82O2tHAfEdtXQEiwOaLDduVeEfBochrnRKnBZMWhPE22dcQtD7vV9uRBVdqGMEfq8ZJB-lTz9qkABw0vuYsB2oLtCJN1rL6aIZQmY/s1600-h/image%25255B36%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMHC-BbgJsWBnd5G6nXivN36thAXwrhBfSSIp4pQmIXGD2zov8lg8gj43bjuR56rt2paZJZ0CcTC4YfCBLlHzw7i0WLgqADHpWhZ89-S5Fltb0cFjLPsixlB0LllMbRi7dRDd5E4DpMPD-/?imgmax=800&quot; width=&quot;512&quot; height=&quot;139&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;So we need to transfer the constructor and add the attribute to this constructor with the keyword &lt;strong&gt;new&lt;/strong&gt; and use an &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd469494.aspx&quot; target=&quot;_blank&quot;&gt;explicit field&lt;/a&gt; &lt;span style=&quot;background: white; color: black&quot;&gt;regionViewRegistry with the &lt;strong&gt;val&lt;/strong&gt; keyword&lt;/span&gt;. In this way MEF is able handle the construction of the class by providing a value for &lt;span style=&quot;background: white; color: black&quot;&gt;regionViewRegistry.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrSYcNlPyrfEyu6MDiMX3ZgoZeTI4J7vWvmaLS5KCxKBrJjA4Qj-FrNgB8FCmFjs78rqjB8BGCHKrZ2JWX4u2FtNaqftHBc_X8nTJz6pOjA2sXv92ducfFI_v7dSmx-jj0-lLCM0XtPaOi/s1600-h/image%25255B40%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzZzngHvDRWkXPUTW2is22n_V6TiKD6g71_C3IaD-_9BaZ3QQjQdhpqeifQfTeHcjz3s3gZfwbpKTJxAsO7RfHsRwv-Gn_OoO-P3XAnjACcpkNzY-gqd79wPmhgE0XcNkiw-NCMuokPHD_/?imgmax=800&quot; width=&quot;639&quot; height=&quot;284&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Now we are ready to test the program. If we run it we don’t get the green Hello World. We need to copy &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0ZDR66N8Z9KQYhysdONeEzX2peerndQOxsKJ646Z-T4BlGS1fxVMngq-UMq0Xn2WUwn1CiOvymFuD001ORhdN-ThxfgdtIMvR7HlLuQ5ceeAI5hAD5yTa6RtZR7-1R02traOPo139Y081/s1600-h/image%25255B43%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8QfC6mMFSoXlu2KuVE87mnCEZIJey7lKuLb5YsDenoWkklA3cbd-mhBHq-BqlsaeR_gMI2LT_vhpqerwjIG6EM5e4Fhib8VSq_SibY1dSUsbG7y_zZghrg_oNCyZXGGkXSOnXy64qnqwO/?imgmax=800&quot; width=&quot;244&quot; height=&quot;79&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;to the DirectoryModules.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglacWDSdD9lB2msjHZ2uCam9RYx0jQ3fPGE6UVeBmWRr6J7SlxxXMlQDUsf3FWD07ywEXq3mUZm20s2Fz7wlPNipY-3iw09tO1cv0vqM3XEj_4q1WT3U45ItIleYYvZF-2ITPr0dN_M53C/s1600-h/image%25255B55%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpLFoShWshkVfh7PzK_tp80JFZcMA5bBVQpmoWzknHzpEH2c_Ee82PLdDww5vXgEUA2lIBgOUMrpz3NmZ7_GKH9-ZQ0RyOvR6XITzR5SqVK0pH6pWHiFKdntYXW1bSnzYvOWY98j4Y_92A/?imgmax=800&quot; width=&quot;523&quot; height=&quot;279&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The dll was dynamically loaded and added to the Shell.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;If you don’t like to copy the dll by hand every time you change it, you could add&amp;nbsp; a post-build event&lt;/p&gt;&lt;br /&gt;&lt;p&gt;copy /y &quot;$(TargetPath)&quot; &quot;..\..\..\DirectoryModules&quot;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgo6c1BTjzor0-AJIjlnIcQZwiNZE58SjUYWVQpJe6MX1tvwWRrPjTydyEzh9WtOllqDrz0vzcuFiPsiXlbhod8S_JBUvogroOqHsFvbY9AZmPA5Ib3Qhy9U_30ExfGxT1SQX7WIPkoILek/s1600-h/image%25255B60%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYk5EloEo-XjKsKEO3zB7SJiuFvA0LoikrUFviDtSst5mcpAOA4ijYsQBDy8ydstGEdewVmK0liOqffQhP0_4nvWum90O5VVcM2aCILgb7UrX6NOxtSswYY05lpM1VxQjuDzUBjcHrXAKj/?imgmax=800&quot; width=&quot;573&quot; height=&quot;319&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;and forcing to build the module.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEVehkMPrbMw-_l8OJmWJn-McFuMLlrR5K2JbTZTzPj9OlJa_HuUfvsGBtdyQq9M8K_S3KcsBD4-eHQRF-YWTmrcSy2j_96O2PFywBhGzy5wY7xJzkdI-VBjeoGn_ikmaA-juyMc1akt-I/s1600-h/image%25255B61%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieqd21AK815zRdHIOyqg0yrr2QnTD3H4wlcISZZoyb4yZSvOKqG3K6Gb-vHP2aqdXgJyDpVWrRW84fOIIQbl2x4UzucysE-N5S_3PO6AthRAu4y3thuyVhrqgWF835zNO4s07Od-yDenrf/?imgmax=800&quot; width=&quot;594&quot; height=&quot;210&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;When we change the color of Hello World to red, recompilation will show us the result in the correct color.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw1Ymsm6I40Rh22b9XuGR9j5Tgxwp4n2WYxdDJdrAP4q2RgFPnq0dyeTgBBtw6t6gge09lIdKdBuik99WbE9ZAa9mu8Sb3EVSt18_7TW8lf5aPFQZDopzhLC0SLFG2p1uptwX7RulL8ftP/s1600-h/image%25255B68%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkijnuDuxE4j7nqE5YcwZ2FOxJtplhStT5Zq3HUJsK9SfAomHAiwp51DLfaRfvsMfY90VcrF2m5g-sU2eJV1sE6wOqc-R5Wa4c-vv-0vsDg5gqmrhpVR9ptARKrRj1eIHibwMqEOXl1M7I/?imgmax=800&quot; width=&quot;663&quot; height=&quot;394&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Next time we will have a look at MVVM by adding functionality to the view and the new Prism 5 ViewModelLocationProvider.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/7312279529515493835/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/7312279529515493835' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7312279529515493835'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7312279529515493835'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2014/06/creating-real-world-wpf-applications_23.html' title='Creating real world WPF applications with Prism 5 and F# (part 2 - MEF)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5heBh1Wa3wOG1PWPv8VtXcts1UcjWVbsZvuGk1Q3iQAk1668an68UTRwqxhrUE12z9pHV0BZ8Y_AmTGe9FlMAHMe_d3mfLVajO7UvwAoc168rCwbuCUQiPzCC0-hcYuB9C6aYBP-fszU0/s72-c?imgmax=800" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-4282163992752987887</id><published>2014-06-16T21:08:00.001+02:00</published><updated>2014-06-17T21:07:14.036+02:00</updated><title type='text'>Creating real world WPF applications with F# and Prism 5 (part 1)</title><content type='html'>&lt;h4&gt;&amp;nbsp;&lt;/h4&gt; &lt;h4&gt;F#&lt;/h4&gt; &lt;p&gt;The designer tools of the Visual Studio should support F#. This would be critical for the adoption of F#. This is what I thought.&lt;/p&gt; &lt;p&gt;Last year I joined a large and complex project. The created system consists of several loosely coupled C# applications. Some components, the clients, have a WPF user interface. Some of the requirements are: easy to configure, extensibility and customization of the clients. It was decided to use modern design patterns like MVVM. It was also decided to create a composite clients. We could have created our own framework, but we decided to use one of the available frameworks: Prism 4.2 of Microsoft.&lt;/p&gt; &lt;p&gt;I learned that Visual Studio UI-designers are not essential for most of the development work. Blend is used by our UI-designers and the number of lines of code in the code behind code files is nearly zero. When implementing modern patterns like MV* (MVVM, MVC, MVP, etc. ), the tools should be great at designing UI’s and should have minimal integration with the code behind.&lt;/p&gt; &lt;p&gt;This leads to the conclusion that designer support of F# in not essential. &lt;/p&gt; &lt;h4&gt;Prism 5&lt;/h4&gt; &lt;p&gt;This year Prism 5 is released. As an experiment I want to build a real world application that consists of: Prism 5, XAML and F# an no C# code.  &lt;p&gt;This application consists of 5 projects:  &lt;ul&gt; &lt;li&gt;The shell, this is the container of the application.  &lt;li&gt;Infrastructure, this is used to contain shared functionality between projects. It contains:  &lt;ul&gt; &lt;li&gt;Base classes  &lt;li&gt;Interfaces  &lt;li&gt;Internal services &lt;/li&gt;&lt;/ul&gt; &lt;li&gt;and 3 modules:  &lt;ul&gt; &lt;li&gt;The Hello World module says hello to the world  &lt;li&gt;The Prime module to determine the primeness of input  &lt;li&gt;The message display module to show the results of the other modules &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Components in Prism are called modules and these modules are not related to F# modules.  &lt;p&gt;The final result looks like this:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg31oBshiaApjZabTisCQvtIoOgtmgbaKl-CmsAy-qaeill_V-iQ39XUJ6YC41Pryhs9wVUKgI7B5zBUMs0Z9VkphUYznycfbpkZ8ZZTAkkO2PiSm-srzxoLIeGiFtdQyUCbdeWlYjuDYu5/s1600-h/image%25255B4%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi34dlYFTy3P_JGikd0ho5A5snWQktAIJjYMGuf8ljZcEKZ3Ha8rk25Y9IEghx_7Cv8P4T3xAe_3Rz9vNuL8M6pZwxuzwViQkIxPuOA4NPsqkO8uBa0AWArZ_f4vtQkoh-PB4JE6OQFO1FI/?imgmax=800&quot; width=&quot;583&quot; height=&quot;458&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Of course this is not really a real world application. It does not contain any really useful functionality and in a real world situations you could choose other ways to solve issues. I just kept it simple. I want to show how you could use Prism 5, its features together with F#.  &lt;p&gt;Prism is a framework created by Microsoft patterns &amp;amp; practices. Prism is composite application framework. One of advantages of using a composite application is the reduction of complexity by separating concerns into functional components. Complexity increases linear with the number of components instead of quadratic and problems can simply be isolated. The details of Prism can be found at: &lt;a title=&quot;Developer&#39;s Guide to Microsoft Prism Library 5.0 for WPF&quot; href=&quot;http://msdn.microsoft.com/en-us/library/gg406140.aspx&quot;&gt;Developer&#39;s Guide to Microsoft Prism Library 5.0 for WPF&lt;/a&gt;.  &lt;p&gt;Prism 5 was released in April 2014. It replaces version 4.2. In the new release:  &lt;ul&gt; &lt;li&gt;The dependency on Silverlight were removed.  &lt;li&gt;Prism was modularized  &lt;li&gt;Contains portable projects  &lt;li&gt;Some components were replaced (the event aggregator) or a new (the ViewModelLocationProvider) &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;All the details of the changes can be found at: &lt;a title=&quot;What&#39;s New in Prism Library 5.0 for WPF&quot; href=&quot;http://msdn.microsoft.com/en-us/library/gg430871(v=pandp.40).aspx&quot;&gt;What&#39;s New in Prism Library 5.0 for WPF&lt;/a&gt;.  &lt;p&gt;&amp;nbsp; &lt;h4&gt;Hello World&lt;/h4&gt; &lt;p&gt;In this first post I will port the Hello World from the Quickstarts of Prism to F#.  &lt;p&gt;&lt;a title=&quot;http://msdn.microsoft.com/en-us/library/ff921141(v=pandp.40).aspx&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ff921141(v=pandp.40).aspx&quot; target=&quot;_blank&quot;&gt;17: Getting Started Using the Prism Library 5.0 for WPF Hands-on Lab&lt;/a&gt;.  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwcEFBDDsWdNHO3pnuGe74b_KK5mDQnR1Z_7ytE55bNLSgr2rDcFhdvHuGODOGdFcKeJzop7tIZdzrniqC-huv0JcK9d-FmGfLWcYH49SDtJcSG0ng6dpFsXQg-P2eKyfcZrxUp2d_JoOQ/s1600-h/image%25255B30%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_Xkf25405RAVyxxHD48QoeG11gtXUc2qgjGaxF5sGGeW6ayrEdnOaPirBbJkxAcqaooEbXwiBFxies33He9926Gbu_avp6Wq0zNqa8NHHbgL_SSXXqrBKFjri1xZhfzoVMEh19RGn6mEJ/?imgmax=800&quot; width=&quot;605&quot; height=&quot;322&quot;&gt;&lt;/a&gt;  &lt;p&gt;I will explain some details of the operation of Prism. Prism does contain a very detailed documentation, the missing details can be found over there. I will also discuss some F# language features. Prism is a framework created in c#, so we have to look at .NET classes, interfaces and inheritance.  &lt;p&gt;Starting point of our port is the F# empty windows app (WPF) template. This template is created by Daniel Mohl:  &lt;p&gt;&lt;a href=&quot;http://visualstudiogallery.msdn.microsoft.com/e0907c99-bb04-4eb8-9692-9333d5ff4399&quot;&gt;F# Empty Windows App (WPF)&lt;/a&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCUI-zJyGlPgQY7-f7-Iqo9QtlcJ_q1Tr1dlAkokr7TwWrQCKubAfdnolDVYF4kzS_pGAn4IaxFuDLNHuraSlrhA4f-kvnB5LEPF9AFOIjrNRh4MWuo674FBQXKMCyk24EzzDXWyykXFLL/s1600-h/image%25255B26%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS39sKWei_37WXnRiqWjikveUtrVCrwwMpXs_YlGxNMuLeZXkFrc1hKdeh3umvoPfCTw_HyQOp9F-qd2ctFtCxcFVzXCeu08BJH8awZjV49sc8aAc045LvUeJf1pLjKOGOFa-ZrTQhAtta/?imgmax=800&quot; width=&quot;494&quot; height=&quot;329&quot;&gt;&lt;/a&gt;  &lt;p&gt;This template will enable us to use the XAML Type provider and it provides us the required assembly references.  &lt;p&gt;After installing the VS template we use it to create a solution and a new project.  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRYlcHWv-gocMGoq3KBUqmebtvQdE1CJJqIbdwl_aNHdw-Axo7MH6ckPnLMPBNNkpeRWpRSAWYyDC7cQMvMOqVPZiQ3vhqOmIOuBvpggK6DKPfNb1DuRYOweXp6HaQCGsNaQw04Svtm3I3/s1600-h/image%25255B8%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiI7joLjbgd75B_JQ9B7GiXgP3xuW2fkJ-9RiFgB3U43kgOU7hBoeHXxCixEGWYXm5ZEx7CGCbqDRL6To6jmX5lba2C1WtUB65aKRsTsvCYjpugv9xjBoyeRFxzR05imKQM1c3Z4YsaUi_y/?imgmax=800&quot; width=&quot;485&quot; height=&quot;331&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This project will contain the shell. The shell is the main component in a Prism solution. The shell does what it promises to do: it is a container and like most containers it is a simple box. It should have no knowledge of the content so the aim is to keep the shell as agnostic of its content as possible.  &lt;p&gt;The Prism shell consists of three parts:  &lt;ul&gt; &lt;li&gt;The view, this is UI part of the shell and is defined is XAML.  &lt;li&gt;The app, this is the WPF functionality to manage the life time of the application.  &lt;li&gt;The bootstrapper, this is the prism functionality to create the infrastructure so the modules can live.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikcX431KJSZie3Ee7RiMGOvVnBqz21u5TpnR_oCxZ1ohgfSsx1l5i-3-Jyro5DgN6rT8cxm-xLwfsfylMihvzRB4e-SFxydJ8KpqTTUGuPwEE7OCW1P-R4Ixk-YcR0Zq1MzrrrBxN80MV8/s1600-h/clip_image002%25255B5%25255D%25255B4%25255D.jpg&quot;&gt;&lt;img title=&quot;clip_image002[5]&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;clip_image002[5]&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-f_oO3Dqo1OLJobTs29pA6NlXwtJh7rIjvALcFcsX1pyWQEgpq4FAHCMQ9RvnGC2IFx4fR8sgkpWLaU_twXZfi0k_AJhd93HyelVcNE7IZLoXzuGFT272DJz02VNs6iWsnXCKq3QV0Qkm/?imgmax=800&quot; width=&quot;332&quot; height=&quot;202&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Then we install the required Prism libraries from nugget:  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKvyFM5kn8f1k1Al4UEShh9ZQR2WO_sBh72SRY3j6mfiN1TKCGyStMJPYNswWAHdKUCAjk1nAK1ayi4xySVopnQ9IcO9rXS6J7LkLRq2xZnjCtWvWNCIdl2o8ilGuJaYHo5MeFg94iNv1q/s1600-h/clip_image004%25255B4%25255D.jpg&quot;&gt;&lt;img title=&quot;clip_image004&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;clip_image004&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLu9zYssQa8egC4TUhGn5Vg15wnFxrfxOl3F5XIPZhUzXFkOdkn5rvKaC6B7myDQPGXjnpJNNrkbeM2rE-56gcmhy9N6wWdDdw5kVNEZozDCf1G6AUea9l8gnXGD8cuYOf3PjYPQiuptpi/?imgmax=800&quot; width=&quot;462&quot; height=&quot;227&quot;&gt;&lt;/a&gt;  &lt;p&gt;Prism requires the use of dependency injection framework. It does not implements its own framework, provides two integrations:  &lt;ul&gt; &lt;li&gt;One with Unity: &lt;a title=&quot;https://unity.codeplex.com/&quot; href=&quot;https://unity.codeplex.com/&quot; target=&quot;_blank&quot;&gt;https://unity.codeplex.com/&lt;/a&gt;  &lt;li&gt;One with MEF (Managed Extensibility Framework): &lt;a title=&quot;http://msdn.microsoft.com/en-us/library/dd460648(v=vs.110).aspx&quot; href=&quot;http://msdn.microsoft.com/en-us/library/dd460648(v=vs.110).aspx&quot; target=&quot;_blank&quot;&gt;Managed Extensibility Framework (MEF)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Both are provided by Microsoft.  &lt;p&gt;It is possible to build an integration with your own favorite dependency injection framework. &lt;/p&gt; &lt;p&gt;The Hello World Quickstart uses Unity.  &lt;p&gt;Next we remove the ApplicationResources.xaml file and rename the MainWindow.xaml file to Shell.xaml.  &lt;p&gt;The Shell.xaml is a simple:&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Window &lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;cal&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://www.codeplex.com/prism&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Title&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Hello World&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;300&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;300&quot;&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ItemsControl &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;MainRegion&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;cal&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;RegionManager.RegionName&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;MainRegion&quot; /&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Window&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The XAML contains two Prism element: &lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;The prism name space &lt;br /&gt;&lt;li&gt;A placeholder so modules can present their content and functionality. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;Next we delete all content of the app file.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;First we add the module name and the name spaces:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MainApp&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows.Controls&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Modularity&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.UnityExtensions&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FSharpx&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Next we make the Shell view available as a type:&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Shell = XAML&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;Shell.xaml&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now we need to create two classes that reference each other. In F# we have to define these classes at the same time by adding&lt;strong&gt; and&lt;/strong&gt;: &lt;br /&gt;&lt;p&gt;App inherits from the Application class, the WPF class manages the lifetime of the application and provide the WPF functionality. &lt;br /&gt;&lt;p&gt;In the derived class we override the OnStartUp method and create a new instance of the Bootstrapper and call the Run method. &lt;br /&gt;&lt;p&gt;The bootstrapper derives from the UnityBootstrapper which derives from the abstract Bootstrapper both part of Prism. The abstract Bootstrappper provides the generic functionality from Prism, the UnityBootstrapper implements the Unity specific functionality. &lt;br /&gt;&lt;p&gt;The bootstrapper has serveral methods that can be overwritten to adjust the bootstrapper. We start with overwriting CreateShell method and InitializeShell;&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;App() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Application()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.OnStartup(e) =&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.OnStartup(e)&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;bootstrapper = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DemoBootstrapper() &lt;br /&gt;            bootstrapper.Run()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DemoBootstrapper() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;UnityBootstrapper()&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.CreateShell() = &lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;window = Shell()&lt;br /&gt;        window.Root :&amp;gt; DependencyObject&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.InitializeShell() =&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.InitializeShell()&lt;br /&gt;        App.Current.MainWindow &amp;lt;- x.Shell :?&amp;gt; Window&lt;br /&gt;        App.Current.MainWindow.Show()&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ConfigureModuleCatalog() = &lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.ConfigureModuleCatalog()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;moduleCatalog = x.ModuleCatalog :?&amp;gt; ModuleCatalog&lt;br /&gt;        moduleCatalog.AddModule(typeof&amp;lt;HelloWorldModule.HelloWorldModule&amp;gt;) |&amp;gt; ignore&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;We end with the start method:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;[&amp;lt;STAThread&amp;gt;]&lt;br /&gt;(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;App()).Run()|&amp;gt; ignore&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;When we compile and run the application an empty shell is presented.&lt;pre class=&quot;code&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTOJmwSF9UIj8xqdFn-U8CKukCG6MbBAFHZEDpL2-wYdW3mMjXyaSMDOtwOSZuK4KfYDMlZ2kdkT8X_WR0CnPhdPXTZdHtVM2aM2obax96gewdbXKbqw6DtfCpWLa5oZDb3pvsEgihsMVA/s1600-h/image%25255B12%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7q1nPucFEN4aaprJvoE47JuIhnk_4YsSzpCmM21d1PsRtBMdnL0VYa-giQgmnD4NtSHPFTlxo93hjW8LXjsemlQmg60Ag4Njd9wvo85r5po8im6txzEsw1qu134yA3h_yITdDjhBWetgV/?imgmax=800&quot; width=&quot;552&quot; height=&quot;413&quot;&gt;&lt;/a&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Next task: create a module that can be shown in the shell. &lt;br /&gt;&lt;p&gt;Create a new project of type F# Empty Windows App (WPF) and change the project output type to class library. One could start with a library project, in that case all required references have to be added by hand. Call the project HelloWorldModule. &lt;br /&gt;&lt;p&gt;Again we remove the ApplicationResources.xaml file and rename the MainWindow.xaml file. In this case to HelloWorldView.xaml. &lt;br /&gt;&lt;p&gt;Next we add references to the Prism dlls. &lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHoRKUVNz4kQQZXEG6tT97czW6w_4E_em5-_fJsqM2kmFQobKZMrh68QtQ2U7bvgltRx40XAFNBu3Z411BbOq1G9Wjg-zcrVzcnt4r6XogaBWuiSNAElYpLo-NeJ5drtFY3UZmZ4OqZPmv/s1600-h/image%25255B16%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIyMsDnIpxan4c4HwQRhFCmMg3E7ThjT_359MbD-YOEj8zZ7ciCQhyphenhyphenJOMH10xHHJEXV5fwwPULjXRlWJVKz77_9PfFcvclvOU53QUYpW5Z0yRcnzSM5tuUYiLsPPUrzJABEqlg-_LtytOx/?imgmax=800&quot; width=&quot;388&quot; height=&quot;169&quot;&gt;&lt;/a&gt; &lt;br /&gt;&lt;p&gt;Again the XAML is very simple:&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;UserControl&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;xmlns&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&amp;gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br /&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Hello World&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Green&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Calibri&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;24&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontWeight&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Bold&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br /&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;UserControl&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;It will show the green text: “Hello World”. &lt;br /&gt;&lt;p&gt;Again we remove all code from the App file. We add the name space and open the required namespaces&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldModule&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows.Controls&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Modularity&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Regions&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Microsoft.Practices.Prism.Mvvm&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FSharpx&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Next we add the XAML of the view as a type.&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldXaml = XAML&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;HelloWorldView.xaml&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now we create the main object of the module: the HelloWordModuel. This is a class that implements the IModule interface of Prism. The interface has one method, Initialize. This method does all the work to make the module available. &lt;br /&gt;&lt;p&gt;In our case we need register the view and add it to the “MainRegion”. This is the region we defined in the shell. To be able to register the view, the module needs access the RegionViewRegistry. It gets this by receiving a reference from the constructor.&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldModule(registry:IRegionViewRegistry) =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;regionViewRegistry = registry&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;IModule &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with&lt;br /&gt;        member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Initialize() = regionViewRegistry.RegisterViewWithRegion(&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;MainRegion&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;HelloWorldXaml().Root:&amp;gt; obj)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The module is ready for use. The last activity is to tell the shell the module exits. This can be done is several ways. The Hello World implementation takes to easy way by adapting the bootstrapper. We add an extra override to the boostrapper. This time we override ConfigureModuleCatalog by adding our HelloWorldModule. The module catalog contains all available modules.&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;App() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Application()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.OnStartup(e) =&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.OnStartup(e)&lt;br /&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;bootstrapper = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DemoBootstrapper() &lt;br /&gt;            bootstrapper.Run()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DemoBootstrapper() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;UnityBootstrapper()&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.CreateShell() = &lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;window = Shell()&lt;br /&gt;        window.Root :&amp;gt; DependencyObject&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.InitializeShell() =&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.InitializeShell()&lt;br /&gt;        App.Current.MainWindow &amp;lt;- x.Shell :?&amp;gt; Window&lt;br /&gt;        App.Current.MainWindow.Show()&lt;br /&gt;   &lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&lt;strong&gt;override &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ConfigureModuleCatalog() = &lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.ConfigureModuleCatalog()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&lt;strong&gt;moduleCatalog = x.ModuleCatalog :?&amp;gt; ModuleCatalog&lt;br /&gt;        moduleCatalog.AddModule(typeof&amp;lt;HelloWorldModule.HelloWorldModule&amp;gt;) |&amp;gt;&lt;/strong&gt; ignore&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;When we compile and run the application the Hello World Module is present, the green Hello World Text is shown.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvKw3CSb74KLvH4HQrEcSom8IdCc7k5nh5hA1NNcYKAhBbMA5uXJkuccb9prU6OnAGqR5vO2kDusV-Q3PO39JuWHj_-kDprrUHPOprlmHC0JpV9UructaRzqbfCnbbwm7iZQbscfdBPLQJ/s1600-h/clip_image002%25255B7%25255D%25255B3%25255D.jpg&quot;&gt;&lt;img title=&quot;clip_image002[7]&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;clip_image002[7]&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaCng-yGhGEL6Jmy5mtqFCHLcVEpzMF4oEtKsu9mrJQTsVP2wxPgodOuQpg1HNABYCAbe1MS-8OPwnJxlxn9hQZCOHqCHP2f8d7EmczZ8tuKuKnfx7DnHyooxNMI6VjNKsheBsnO9LEzpS/?imgmax=800&quot; width=&quot;534&quot; height=&quot;278&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;This completes the port of the Hello World from the Quickstarts of Prism 5 to F#. &lt;br /&gt;&lt;p&gt;There is at least one problem with the Hello World implementation. The Shell has to have knowledge of the HelloWorldModule. &lt;br /&gt;&lt;p&gt;Next time we have a look how we can fix this. There are other ways to configure Module Catalog. If we use Managed Extensibility Framework (MEF) as the dependency injection framework we can even can reduce the configuration to copying module dlls into directory.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Updates:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;I got a tweet from Reed Copsey (&lt;a href=&quot;https://twitter.com/ReedCopsey&quot;&gt;&lt;s&gt;@&lt;/s&gt;ReedCopsey&lt;/a&gt;). He suggested to use &lt;a title=&quot;https://github.com/fsprojects/FsXaml&quot; href=&quot;https://github.com/fsprojects/FsXaml&quot; target=&quot;_blank&quot;&gt;FsXaml&lt;/a&gt;. By getting a version via Nuget:&lt;/li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzz8D6Co155-6Qr9bTm34yrtqg4RHpODnqkHDQ8ccFI67ZPCzzVKaJpy8PVDGxgBZgZLuJWg-PeiVe9Ibuf2NeSOTBd70L8EiBtXpj6LyxRhQQvg5zygGWFgSuWHkNoAgCh5tpwuHmunVy/s1600-h/image%25255B10%25255D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqdbhYytCDpLe4uoWajowI42NOcYRJ0ozmgJzLqPnfw2zARfHlNkb0deyZiOVtwlnYZOfSOwbiy9qgpPjEggrAk53K7wvIjP1rJEf6ToTpNr9W7snWQFboXcwZOjldaJ7lLMSmpX8Sb_q-/?imgmax=800&quot; width=&quot;436&quot; height=&quot;98&quot;&gt;&lt;/a&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;replace the namespaces:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FsXaml&lt;/span&gt;&lt;/pre&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;and adjusting the creation of the view:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DemoBootstrapper() =&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;UnityBootstrapper()&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.CreateShell() = &lt;br /&gt;      &lt;strong&gt;  Shell().CreateRoot() :&amp;gt; DependencyObject&lt;/strong&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.InitializeShell() =&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.InitializeShell()&lt;br /&gt;        App.Current.MainWindow &amp;lt;- x.Shell :?&amp;gt; Window&lt;br /&gt;        App.Current.MainWindow.Show()&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;override &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ConfigureModuleCatalog() = &lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;base&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.ConfigureModuleCatalog()&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;moduleCatalog = x.ModuleCatalog :?&amp;gt; ModuleCatalog&lt;br /&gt;        moduleCatalog.AddModule(typeof&amp;lt;HelloWorldModule.HelloWorldModule&amp;gt;) |&amp;gt; ignore&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;it works again.&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;I have posted the source code add &lt;a title=&quot;https://github.com/PsAccelerator/FSharpPrism5&quot; href=&quot;https://github.com/PsAccelerator/FSharpPrism5&quot; target=&quot;_blank&quot;&gt;FSharpPrism5&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/4282163992752987887/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/4282163992752987887' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/4282163992752987887'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/4282163992752987887'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2014/06/creating-real-world-wpf-applications.html' title='Creating real world WPF applications with F# and Prism 5 (part 1)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi34dlYFTy3P_JGikd0ho5A5snWQktAIJjYMGuf8ljZcEKZ3Ha8rk25Y9IEghx_7Cv8P4T3xAe_3Rz9vNuL8M6pZwxuzwViQkIxPuOA4NPsqkO8uBa0AWArZ_f4vtQkoh-PB4JE6OQFO1FI/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-7218525624364550537</id><published>2013-06-17T15:46:00.001+02:00</published><updated>2013-06-18T08:21:53.344+02:00</updated><title type='text'>Increase your productivity with F# scripts (part 2)</title><content type='html'>&lt;p&gt;Last &lt;a href=&quot;http://ps-a.blogspot.com/2013/06/increase-your-productivity-with-f.html&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; we discussed a real world problem, cleanup your test environment after a complex integration test. We used a F# script to do the work. &lt;/p&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt; &lt;p&gt;This time we look add more advanced scenario’s and solutions. First we want to split our script file into two files. One containing the scenario related code and one containing a library of facade function we want to reuse.&lt;/p&gt; &lt;p&gt;We start by creating a new script file in the Scripts directory calling it Lib.fsx and open the file with a text editor. Next we open also the script file we created last time and add the following lines of code:&lt;/p&gt; &lt;p&gt;#load &quot;Lib.fsx&quot;&lt;br&gt;open Lib&amp;nbsp; &lt;p&gt;The first line links the script file to the newly created Lib file. The second line opens the namespace “Lib”, the default namespace of the functions in the Lib script file.  &lt;p&gt;Next we move the facade functions (including the reference to the namespaces) to the Lib file.  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6_r-KzZa6_cJ51264pL2AMmGACDQJ1nbJUh7Z19n8yMStABJvWmxAyi2MfBVamcugnZ6TV8MaVwKZyTQWvdXeo3kfRtYLxpotVT4LKuGJpmyay0dLzhn84Hlya_nmK7w9xEnEvF-HAT0i/s1600-h/SplitSource3.png&quot;&gt;&lt;img title=&quot;SplitSource&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;SplitSource&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMfOX_hsNJ9_UNjIoZyfnwT2naqnpvekG0z6eUz4S8byCkDNTPtbMo-YW0v4CPek7fnQPRqy0SXkXCpP4-dIL1uScsMklY9lXc9Tzl-UF1SrTd3SZBuW2T9mUGYV_2jz6jyvN8mrs8SDWw/?imgmax=800&quot; width=&quot;664&quot; height=&quot;366&quot;&gt;&lt;/a&gt;  &lt;p&gt;After this refactoring everything still works the way it used to work.  &lt;p&gt;Next want to create a startup script. Every time we start the laptop we want start with a clean log directory, we like a clean machine and second we want open a Visual Studio Solution so we can start coding immediately.  &lt;p&gt;We start by creating a new script file called Startup.fsx and the following code:  &lt;p&gt;#load &quot;Lib.fsx&quot;&lt;br&gt;open Lib  &lt;p&gt;[&quot;E:\\Log&quot;] |&amp;gt; List.iter(deleteContentOfDirectory)  &lt;p&gt;Again we connect to Lib file and reuse the deleteContentOfDirectory function we created last time to clean the Log directory.  &lt;p&gt;Next we create a new shortcut like we did the last time:  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKAL9g7Gq-hgn0vlk5jS8Mjl6MGu9A1UARR3_Xn5930b4eLdNvX81uLqJb6vgpwLtZj7RxlkKjNaSMSlyLSELq5nw_7jw2aPruOCITz5VXwv-_sQVX9GTKzDsRKr96cbF-yWkapUsTW41U/s1600-h/StartUp_Shortcut3.png&quot;&gt;&lt;img title=&quot;StartUp_Shortcut&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;StartUp_Shortcut&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOWI0eqjZCRU7eq73Nxja6DN7vhI5rllSyhKGbSrnUSzLDRmDxfBgujiG20Rtr2cfStUcBX97f4FJsZuXkvgpXv138EnpT8asG5SO387JugTs0U5-tUDTvX3zwGhEepR9U-wGqfT84eIqW/?imgmax=800&quot; width=&quot;542&quot; height=&quot;340&quot;&gt;&lt;/a&gt;  &lt;p&gt;This time linking it to the Startup script.  &lt;p&gt;After testing the script we move the shortcut to the following directory:  &lt;p&gt;C:\Users\&lt;strong&gt;YourAccountName&lt;/strong&gt;\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup  &lt;p&gt;&amp;nbsp; &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGvFokMJWMyCf49UD7J27yH7en5C4UYO1R3ylgzfnbweYrn4bHv1qPVa-F0rYFzojkq3Cys8oTjDQ8UGzGIe5CeciaAfA0n-u8MwbVf5-Z_iElcdIFzHnEckWqdrudxMx2NvcqCBeH930Q/s1600-h/StartUp_3%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;StartUp_3&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;StartUp_3&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjecZISokiY_UtMn0EyJ7jBl-uIEEJEwwW4ajq0uBNHjw986X1hDuO9AGi1pk-hoyJH2PzH-tYkRlCPHkr3YxPELMi3tVXt2ab4qRgypsCixXRBM64e7c_8OseRfNGVXSWPqbE7uI7Zm1Le/?imgmax=800&quot; width=&quot;464&quot; height=&quot;90&quot;&gt;&lt;/a&gt;  &lt;p&gt;After we restart our machine, the Log directory is cleaned.  &lt;p&gt;There are other ways to associate scripts with the startup. You can use the &lt;a href=&quot;http://technet.microsoft.com/en-us/library/cc779329(v=ws.10).aspx&quot; target=&quot;_blank&quot;&gt;group policy&lt;/a&gt; if your version of Windows has access to it (&lt;a href=&quot;http://blogs.windows.com/windows/b/bloggingwindows/archive/2012/04/16/announcing-the-windows-8-editions.aspx&quot; target=&quot;_blank&quot;&gt;gpedit.msc&lt;/a&gt;):  &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuX2vp8l_TEZvN_pdx0E-Sa8aEOUDtIDRwl6aKNDj9zTaHm-kcktOnLaCujVUii24-EzCUfuSkH-pPf-vd5hkch4LGlg4NuOApegASY66Ni1dzw7Ev1Q_iyA51skZBz0Nwa6TRF30ujqxn/s1600-h/LocalGroupPolicy_1%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;LocalGroupPolicy_1&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;LocalGroupPolicy_1&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-wTyMBk3gfReAF9eubKSDLXYqtdF4QQBXxRrOmtU1d97QjrPAVJEefVhJ2hsKXfh9mv8Hag5425bThNyZeEsUkCPJS9gRPvrdKHCvm7FwLVqPNi3TKvW7bPNNSb3n-PW4nhtYEVEkQQI9/?imgmax=800&quot; width=&quot;599&quot; height=&quot;366&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Next step is to open the Visual studio solution.&lt;/p&gt; &lt;p&gt;We add the following facade function to Lib.fsx&lt;/p&gt; &lt;p&gt;let startProcess fileName =&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; let newProcess = new Process()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newProcess.StartInfo.FileName &amp;lt;- fileName&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newProcess.Start() |&amp;gt; ignore  &lt;p&gt;and the following line to the StartUp script&lt;/p&gt; &lt;p&gt;startProcess @&quot;E:\VS\Test\Test.sln&quot;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlisjFIlkUJwSy-hOGLs2AlC2oxtV8C2P0Ef_2AWMmVWV-wfap0oZJkMQ9CKpiHDJCqMtNPsrx9ybnEDBTUwoUodvMT-kZUasNpTuCjs7GIlBXT2hK8GMoMwJZQDElXfH5-yZn2ChdG1zj/s1600-h/VS%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;VS&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;VS&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg39NN3gYIxClqJJPTmselRoO7dgzyCV66qE4_PjwLSn2rQc4bcEvHefZq88osQ8rUcescyW41aRn8GTpHRnFm3zK74UQvIGM02iDDGxz9b9l97FT563KqLxMdIMfYgpJhFubC6nmKzyvdF/?imgmax=800&quot; width=&quot;394&quot; height=&quot;285&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;the next time you start up the log directory is clean and your Solution will be directly available.&lt;/p&gt; &lt;p&gt;Adding extra functionality to the scripts is now a trivial activity.&lt;/p&gt; &lt;p&gt;My Lib files contains, for example, exception handling and some reporting:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnHEZ-oky5g32IQ39UToT0jqXe-j1MmLyi9A8wFswB8JmXwEbWE-bCK9mrEqiz1GUy0vaDbC2mHAddU1LyvEXGSA07xywQzdiOAGjw8MPyy0E0tjyecyY5HjZ_XMVABebOLJnF-qJObirA/s1600-h/ExceptionHandling%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;ExceptionHandling&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ExceptionHandling&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisPNyDp3Ptv_aIawIbayiz6wwVSW5SHsZwD_cnUwL9Bfrvrmv_Gr3wHfUQEf8VkUbJFxGMtsIekDcfZg5cANWGUrSJHWHY7kBf05RsPUsVu0Hf3nygZvM-Gn49UO_QSK7R4Dp-oy1IleV4/?imgmax=800&quot; width=&quot;625&quot; height=&quot;290&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;This will not stop the script in case a file can not be deleted. The exception will be reported to the console.&lt;/p&gt; &lt;p&gt;There are a lot of activities that can be automated, I have scripts that:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Start programs like a mail client.  &lt;li&gt;Creating zipped backups of source code.  &lt;li&gt;…&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In this way I can improve my productivity with F# scripting. How can F# scripting increase your productivity?&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/7218525624364550537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/7218525624364550537' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7218525624364550537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7218525624364550537'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2013/06/increase-your-productivity-with-f_17.html' title='Increase your productivity with F# scripts (part 2)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMfOX_hsNJ9_UNjIoZyfnwT2naqnpvekG0z6eUz4S8byCkDNTPtbMo-YW0v4CPek7fnQPRqy0SXkXCpP4-dIL1uScsMklY9lXc9Tzl-UF1SrTd3SZBuW2T9mUGYV_2jz6jyvN8mrs8SDWw/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-689554614751211217</id><published>2013-06-13T16:23:00.001+02:00</published><updated>2013-06-18T08:23:12.939+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Script"/><title type='text'>Increase your productivity with F# scripts (part 1)</title><content type='html'>&lt;p&gt;&amp;nbsp; &lt;p&gt;One of the many nice features of F# is its scripting capability. There are other scripting languages like PowerShell to improve your productivity on a Windows system. In this case you need to learn a new language and a new environment to automate some basic tasks. When you know F# and .NET you can leverage your skills, so let’s look at F# scripting.  &lt;h2&gt;&amp;nbsp;&lt;/h2&gt; &lt;h2&gt;A simple real-world problem&lt;/h2&gt; &lt;p&gt;I once was responsible for integration testing a complex set of applications. After completing the test several applications were still running so these processes had to be stopped with the Task Manager and several directories had to be cleaned. How could F# help me to be more productive?  &lt;p&gt;Let’s start by creating a directory called Scripts, add a new text file and rename it to EndIntegrationTest.fsx. &lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipaP34B3eOJZv6vWPBU1tvyaN5UdbXb-GwVncgyVQoYezGyblWN3fXroSmCU_9H_mGfvJn5hhNBjmdnDbDyzahZUsb-DAvFb0oTXxA4p39UiZD4kkqEeneYxwdz7Nl2j5UTlMotWTib_m9/s1600-h/Create_EnIntegrationTest3.png&quot;&gt;&lt;img title=&quot;Create_EnIntegrationTest&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Create_EnIntegrationTest&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdsaXlzs_AsQDoTcKmYJVoioXLc_FIsVEIOmGf0HtcFoFfT3vnUg9V4gTGnFc_FD5w5DPjSQQoNBL7zFhTgy3fba0HFIRiLOiedtaY5a2hwqOcuQWYcPQspXPpOAtjkcq2e1VpOWsTCp3Q/?imgmax=800&quot; width=&quot;484&quot; height=&quot;127&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;open the file with your favorite text editor, I use Notepad++ in this case and&amp;nbsp; &lt;p&gt;add the line:  &lt;p&gt;System.Diagnostics.Process.GetProcessesByName(&quot;app1&quot;) |&amp;gt; Seq.iter(fun x -&amp;gt; x.Kill())  &lt;p&gt;This will “kill” all programs that are called app1 by first looking for all processes called app1 and next kill them one by one.  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtMOWPQ6kTTvxkXlXhoIbUDL93E9XEd-bciwDczDOewsZQRN4_VTFjJF202No8DX2nLCxBqhQGDMy9RO85p263SCX8PGJFiQiCw__TkPSClpdxgioAim-TA6DSY29UqXveR_ijj38B4PF_/s1600-h/Create_EnIntegrationTest_13.png&quot;&gt;&lt;img title=&quot;Create_EnIntegrationTest_1&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Create_EnIntegrationTest_1&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB1NrZ_GpbD3Yu6Bc56KvC4t4MuTeIsj6-RgQtKbmcbEIS1TXBum5hyjpUTXl7Zk5V444MajzDQ5feSHvtqODxstRTJ431igEaVfIWEGcdLXeeUutfl-ENuxD7n8jvWu3u2CffZHLD9yOO/?imgmax=800&quot; width=&quot;585&quot; height=&quot;136&quot;&gt;&lt;/a&gt;  &lt;p&gt;I have set the Language menu to Caml to get some syntax highlighting.  &lt;p&gt;Next we change the program associated with the file extension, right click:  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAoJC-SYjGGRkG8Z1_ShdenO99w-CSXofx31oUY7yLX2gBTNNZcvAbqXEzzNL9WrpCh1Fna2A9kTHsM0hoQmD_n4fF-j0hY1eXB6CgC5m3E0EO9rxaqcpLLXeCVmH_k2g9YSZfqbZYF8IU/s1600-h/ChangeProgramme3.png&quot;&gt;&lt;img title=&quot;ChangeProgramme&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ChangeProgramme&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4jqIyYFq-XzbO94ps5vrf0_JYSGT9vS615bCxU6x_TuYBwQxu6kEb8loPPZhyphenhypheneQdAi3QuiPetw4iR3E1oN1WIDHvqbbvINlKG1XstHZ9_tYPsDDdw2dVqjY1Y2B_WRkh3siWUmYzov-MD/?imgmax=800&quot; width=&quot;517&quot; height=&quot;361&quot;&gt;&lt;/a&gt;  &lt;p&gt;Look for another app on this PC (this is Windows 8) and look for the following directory:  &lt;p&gt;C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij-8-xBrqJzBXMIRUGGYpBXlqp-G6DO7iHewQVErtE094We7kKJKYd9Y9HM9y-MaV36oToT-vYhgk93KUsKEVlJo14lfguzmPAZKP14VmqGMgyx3uh8M5swMZYVe5rrFYJhPRoseIvfVkq/s1600-h/Fsi3.png&quot;&gt;&lt;img title=&quot;Fsi&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Fsi&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLu0swLB7ZVh8E4iQ8Tw3Og2iVTyI58991hV66AhihhoLZ5m1obaDDURegi6xVgav2P4QVuGZCCll_AHLbA1cG8TgO0FP0Zhf-s11y1D8SmroZxMpIas6IgDGcg05EJ4jLFEMfEhFj5ivV/?imgmax=800&quot; width=&quot;572&quot; height=&quot;177&quot;&gt;&lt;/a&gt;  &lt;p&gt;and select fsi.exe.  &lt;p&gt;To test the script I created a C# console app and called it app1, start the executable in the debug directory  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieVdHRU6Z0B4fNt1bAacRrzrNhVde9GFveOm00QYNOLUEDuKfpy5akwdKnKuNd6jQce9lxifHIflz6YPancb9l_tz2At4KXlD59NX8MbEs5cUP7bb64jJ3z9aywpjINJrBrK5f7Jc-z57t/s1600-h/Before3.png&quot;&gt;&lt;img title=&quot;Before&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Before&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgthBD5h5sX7eOrYkNulMfiIzHnmSi1Ot8mmnJcWJaL5n-HDO_82qGkKdp3_xO8Mru0Nd5e9SUyHF3rBmy8nZA9WnmcQrj4XSywZs0HrdelL4JEixgHkGBZdzXSH1Z9rHb8VxbgF2sJGl8j/?imgmax=800&quot; width=&quot;532&quot; height=&quot;412&quot;&gt;&lt;/a&gt;  &lt;p&gt;Open the script file and app1 will be killed (R.I.P. app1).  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWcVVRtgz0JMkPMeJ_o6zwiyqk_bCpgeYWWQ-Tad72XyddaxT_UzktVebvdBn6ninmUw0VOIrb0qE2ibfwb-Nio2ijjadHsGJ1KfotX7xCRdw1wwwFw5_X0FJqou4Zwl2da1fxYLvE0e5e/s1600-h/After4.png&quot;&gt;&lt;img title=&quot;After&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;After&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRr7_BwzHldosJG4ziZUpecqnBD4Q-v2yHV3blc1B-Ldq1Bp5yaj3Bfdu3m6d2qU-z2D_TYJcg0Jof02cyVFs6I0BuZY5gERLNnEBrxumZZOClqyfJXXzxyNz8uNRjyzuVoy_737Gd7r8-/?imgmax=800&quot; width=&quot;539&quot; height=&quot;348&quot;&gt;&lt;/a&gt;  &lt;p&gt;This scripting solution has some drawbacks which we will discuss later, but it works. It matches the first rule of scripting:  &lt;p&gt;&lt;strong&gt;Keep your scripts as simple as possible&lt;/strong&gt;.  &lt;p&gt;Scripts should increase your productivity and you should not spend much time on debugging or creating functionality you do not need (YAGNI –&amp;gt; &lt;a href=&quot;http://en.wikipedia.org/wiki/You_aren&#39;t_gonna_need_it&quot; target=&quot;_blank&quot;&gt;You aren&#39;t gonna need it&lt;/a&gt;).  &lt;p&gt;In case I want to kill app1 I have to go to the scripting directory. I can become more productive if I add a shortcut to my desk  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz9O8Eu_ogis8m8S01WmxczICinFkj4Cl3roxI0j23hJDpNE5W03OAqcbpjbOUA5CM6osWyGkzoIUufD9yzrwbqiyIhyphenhyphen6sUP2qingvcKbrv6AuKPu_zgsaW4WOmngqAgOnlArT_sHKG_xx/s1600-h/CreateShortcut3.png&quot;&gt;&lt;img title=&quot;CreateShortcut&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;CreateShortcut&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUF7nEV2w-uDSPQZU4Qo3w4W3zgW2SM55qvFv0BDU8ETJftPGqpvwRjr5fSQD8FJHiJU-K3JEDI-c0ek1EVos9k7bkC99kJ3t7ecLem_zVIbaBhyVv2LF0PrtOqGHoV6-dG5mca4ggIqh-/?imgmax=800&quot; width=&quot;286&quot; height=&quot;198&quot;&gt;&lt;/a&gt;  &lt;p&gt;rename it “Shortcut_EndIntegrationTest” and move it to the desktop.  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEwV42vgsPMXA94Gc6DYAn7jdNJDql8Yz6GGJrJjKtZPSr0_5ayTwgrA8HsNQH2GBAP8x0dCb_nlPKDqoGOXC0PpCKou410orJSSK4dj59o-7wHswC3fm1ZIo87MdmBu2DyxIczh2jpl00/s1600-h/Shortcut4.png&quot;&gt;&lt;img title=&quot;Shortcut&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Shortcut&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC4FWdI9HSEJXPV0aV1b9LB2aJP9-oeImyR1Sk_-KpvDNCXaAUOKPKt4PAYO0FeszlVmxAvIg4_w8ZnUqjbJKUYBe667kAMFAL56s-C3SdgkTl7qFmSlr0pDHLC3sSuDg2MOJQZkdzW6HU/?imgmax=800&quot; width=&quot;255&quot; height=&quot;154&quot;&gt;&lt;/a&gt;  &lt;p&gt;The next step is to change some of the properties of the shortcut, Shortcut key and Run,&amp;nbsp; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHgX-qVBTbubJ8a8hyhfD1rdhGuFK1bTC9nR-NqA0yJgevloImDxHTGpi4a24hyiXx_cLQJROqokLTDNyTrDERMtgRKikzMGv6uEHWo1bgLSGg3IzdOUhEhmfV_Wn7UMIA8AQWEdAnVHYX/s1600-h/ShortcutProperties3.png&quot;&gt;&lt;img title=&quot;ShortcutProperties&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ShortcutProperties&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcx9h2CpfDNG27hVKs10LkvSHyKUkMhRgFF2dKpj1Cohkr8Fmj0d3nSIuPQRbzH0t-2K-vJRhX_B0XB1qIXfv4K19CwQxsnPa3y5iyi_ETHuOKCtG1dux8oxcvnKmxbVZufzUOMahuIC92/?imgmax=800&quot; width=&quot;376&quot; height=&quot;325&quot;&gt;&lt;/a&gt;  &lt;p&gt;After these changes all I have to do is press CRTL + ALT + 1 after the test is completed and the script runs without showing a console.  &lt;p&gt;One of the drawbacks of the the created solution is that we have associated the .fsx extension with the fsi.exe. In this way we can run an F# script by accident when we just want to edit a file. With great power, comes great responsibility. We can fix this when associate the .fsx files with a text editor program and repair the shortcut. Also from a security perspective this is a better solution.  &lt;p&gt;Go to General tab and associate .fsx with an editor  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif4JNprVCWmYZK0JQt35FwDL1CdD4_38rwYp3PIqFaOZyIt2VaK0y7cl65vApKpKGtaHeShG6owxjLoldl8MKeXh7-hAJEZowgVILh1m_YT0Gr1l-sLU4uaTLAFsH6HQDVsa6WZtoWedcQ/s1600-h/Notepadd3.png&quot;&gt;&lt;img title=&quot;Notepadd&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Notepadd&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVufCRyfg2lBCHDsxWmR0r9WoQB1pLoFcbUY8T_d7HBffQ7SvNC8dbf-DRLEHdx1leaVKoz0W7WkTNpD2uAb6lI4H-SeYb5bLO5arGKsTaE0QKqQG1OA5BbMpVnW8lj6UhGJPW3it9I_Da/?imgmax=800&quot; width=&quot;458&quot; height=&quot;333&quot;&gt;&lt;/a&gt;  &lt;p&gt;After apply the shortcut and all .fsx file will start the text editor.  &lt;p&gt;Next change he target line to:  &lt;p&gt;&quot;C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0\Fsi.exe&quot; &quot;E:\Blog\Scripts\EndIntegrationTest.fsx”  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnfpxus_2IdcVKgKX_Ngu7xruph-VSQ8KxlsVBk8pW5d8BRNyEYg6tJou11Nog5jwtnRufS_Lrgezr1ARQvjqAKKorqC6L30NDOORJub-dP9onIcIyQbBk9qW52pNqgZbRLX_XbjVEXj9c/s1600-h/ShortcutProperties7.png&quot;&gt;&lt;img title=&quot;ShortcutProperties&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ShortcutProperties&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWeRxjAZPOUxWugOixH3HFqw3Z6D-Pcxo0hx8NnC4HAD4xdjzP7Zv02yFcjaRTGSjN9Xs5i3SRUJYVIcU7tWxzQNrwt1dokw-hEpdzZWJvp94vyaorptHWkXPC2KAq_4Kg9cgpNG46rMLb/?imgmax=800&quot; width=&quot;367&quot; height=&quot;405&quot;&gt;&lt;/a&gt;  &lt;p&gt;and the shortcut will kill app1 again (you need to repair the shortcut key and the run mode).&lt;/p&gt; &lt;p&gt;This script does not solve all our problems, we have to be able to kill multiple applications and we have to clean all polluted directories.&lt;/p&gt; &lt;p&gt;We could copy the line that killed the application and change the name of the app, but there is a second scripting rule:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Do not repeat yourself&lt;/strong&gt; (&lt;a href=&quot;http://en.wikipedia.org/wiki/Don&#39;t_repeat_yourself&quot; target=&quot;_blank&quot;&gt;DRY&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;So we create a facade function killProcesses:&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Diagnostics&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;killProcesses processNames = &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Process.GetProcesses()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;gt; Seq.filter(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;p &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;processNames|&amp;gt; List.exists (&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;name = p.ProcessName))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;gt; Seq.iter(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Kill())&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;and call it with a list of application name:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;killProcesses [&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;app1&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;app2&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;]&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;this replaces the initial code.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWAyt8aElDelP14FqJnKnFUgs3ZRg6D1f_V1wXGLEySZKg-5yI6I726ujbfWYBRB4ZBMG7jcXsTbZwgzqsvh_bmpPL-NZkBgA4hBQRzNeUfqfj0V6exgJlCDK-LAov7_evAsCmsZylxGb_/s1600-h/killAll%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;killAll&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;killAll&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE8SQ6crJbgQKXuKW6AtoF_HBHNTiidc9mf2GQ-sw1REYzqtKNWkgFrCINEuRqKmp7lKKaegqHd6XVxbNvLL3G4TXLFGQJ9cl_T8yoF18LZ9xy-mPh9bH6MfV-CV1c8ZxFqYmkZf9hAng9/?imgmax=800&quot; width=&quot;438&quot; height=&quot;223&quot;&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;CTRL + ALT + 1&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;and all are processes are killed.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Next we add the facade function to clean the directories:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;deleteContentOfDirectory path =&lt;br /&gt;   Directory.EnumerateDirectories(path) |&amp;gt; Seq.iter(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;dir &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Directory.Delete(dir, &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;))&lt;br /&gt;   Directory.EnumerateFiles(path) |&amp;gt; Seq.iter(File.Delete)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;We enumerate through all content in the directory, sub directories and files and delete them all. We use the facade function to clean all required directories:&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;E:\\CleanUpTest1&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;E:\\CleanUpTest2&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;] |&amp;gt; List.iter(deleteContentOfDirectory)&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Before:&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtC_aE4-MKWXXcmy7MXHoHj6iIh6aHrsBRMScJBOi6a1YntBotXnpSA3dsC2t_AwqjQnq0sTKYcvvItZUtkbG23dyOvLFDYkK6OZVeLDs22TzHS15Ha_zti3TmWCGbtHTxZlJ8KJ6D8iz6/s1600-h/CleanDirBefore%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;CleanDirBefore&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;CleanDirBefore&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijOzCwB5fXeJbU8YZzb20vc-05b8sKeK3ibQG4s_swCey5yqo8xADrE38O5p5c7gVM8_Ip2ANDwIDYHj_ZcL0P0O4yYoPYx1dGBhJWhOWbmtC8Z2U0mTzjxAwYMdomGXplRBcx_2c0ao7g/?imgmax=800&quot; width=&quot;670&quot; height=&quot;313&quot;&gt;&lt;/a&gt; &lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;After:&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO3DEJ6gF13BCHx-kb5vo3hlJ3N2gHsHZNaFYFzCIbgRGLf6ceMUqWkF7Z8T8Gex631C7SLNOpp3v3ub-Eor1Q0pBlD9Fx2ksrOOyZ1dn1MP_OdFsE9o4erSy1b6cxzMrCZlJI9VqhDbkh/s1600-h/CleanDirAfter%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;CleanDirAfter&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;CleanDirAfter&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCrymn5qCUCUtljNiiJknL_jbyDRGVM1zdghhRreSzNim8k3xDC10nM-J34VSufhGBNAX4Ib7l_L7rf9X5ItwvBJNnOWMO3B9XZZS2EsXXVm9fPtOfTliVsfleazNXc-U_1sgfmLa3vnWm/?imgmax=800&quot; width=&quot;684&quot; height=&quot;227&quot;&gt;&lt;/a&gt; &lt;/pre&gt;&lt;br /&gt;&lt;p&gt;So we have solved our real-world problem.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;http://ps-a.blogspot.com/2013/06/increase-your-productivity-with-f_17.html&quot; target=&quot;_blank&quot;&gt;Next time&lt;/a&gt; we improve our solution by putting the facade functions in a library and we look at startup scripts.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;:At a windows machine not containing F# Script (REPL), you can add it yourself. Here are all the details: &lt;a href=&quot;http://blogs.endjin.com/2013/05/a-step-by-step-guide-to-installing-an-f-repl-environment-on-windows/&quot; target=&quot;_blank&quot;&gt;A step by step guide to installing an F# REPL environment on Windows&lt;/a&gt; by &lt;a href=&quot;http://blogs.endjin.com/author/matthew-adams/&quot; target=&quot;_blank&quot;&gt;Matthew Adams&lt;/a&gt;.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/689554614751211217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/689554614751211217' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/689554614751211217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/689554614751211217'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2013/06/increase-your-productivity-with-f.html' title='Increase your productivity with F# scripts (part 1)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdsaXlzs_AsQDoTcKmYJVoioXLc_FIsVEIOmGf0HtcFoFfT3vnUg9V4gTGnFc_FD5w5DPjSQQoNBL7zFhTgy3fba0HFIRiLOiedtaY5a2hwqOcuQWYcPQspXPpOAtjkcq2e1VpOWsTCp3Q/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-429451765613465411</id><published>2013-01-29T14:05:00.001+01:00</published><updated>2013-01-29T14:07:39.165+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Collection"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Binding"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="MVVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows 8 Store App"/><category scheme="http://www.blogger.com/atom/ns#" term="WinRT"/><title type='text'>Windows Store Apps with F# (part 4) : Collections</title><content type='html'>In the previous &lt;a href=&quot;http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-3-data.html&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; we were introduced to data binding and MVVM. We dealt with one object. How can we deal with more than one object, a collection of objects?&lt;br /&gt;
This time we want to show a sequence of primes:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;2
&lt;li&gt;3
&lt;li&gt;5
&lt;li&gt;7
&lt;li&gt;11
&lt;li&gt;…&lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/ol&gt;
The first number is the sequence number, the second is the value of the prime. We want to show this sequence in a Windows Store App.  We create again a new blank Windows Store App and add a F# Portable Library. We rename the F# file to Lib.fs.  Let’s follow MVVM. We start with the Model. Add the IsPrime function to Lib.fs:&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;MathLib
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;IsPrime n =
     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;n &amp;lt; 2L &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;then
            false
        else
            seq&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;{2L..n - 1L}
            |&amp;gt; Seq.exists(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;n % x = 0L)
            |&amp;gt; not&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;Next we create an object to represent an element in the sequence:&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;Element(sequenceNumber:int, value:int64) =
    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;x.SequenceNumber = sequenceNumber
    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;x.Value          = value&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;Now it is possible to create a function that will determine the next element in the sequence of primes:&amp;nbsp; &lt;span style=&quot;background: white; color: blue;&quot;&gt;let rec &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;nextPrime (element:Element) =&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;IsPrime (element.Value + 1L) &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;Element(element.SequenceNumber + 1,&amp;nbsp; element.Value + 1L)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;Element(element.SequenceNumber,&amp;nbsp; element.Value + 1L) |&amp;gt; nextPrime&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;Next we create a sequence of all primes (details at page 320 of &lt;a href=&quot;http://www.manning.com/petricek/SampleChapter12.pdf&quot; target=&quot;_blank&quot;&gt;Real-World Functional Programming&lt;/a&gt; by Tomas Petricek and with Jon Skeet, buy this book!!):&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let rec &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;primeSequence =
    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;seq &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;yield &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;Element(1,  2L)
          &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;for &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;in &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;primeSequence &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;do yield &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e |&amp;gt; nextPrime }&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;and test the model by adding a test to the Script.fsx file. &lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;#load &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;&quot;Lib.fs&quot;
&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;MathLib.primeSequence |&amp;gt; Seq.take 5 |&amp;gt; Seq.iter( &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;r &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;(printfn &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;&quot;%d. %d&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;r.SequenceNumber r.Value))&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;When we run the code in F# Interactive we get the expected result:&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoIFbpMRKTPY3QGYmjLrarsdwWUGveUSVgJDxe_ilshiXYBWuBDwpjhx5sl1XfPS9ibbbrF4G1Y-7bH923jIT8FN4XxNT2qmpI67Ys6JsovKGuBcSLTdPNxa0GSATZdOmClCwuupxaAB0C/s1600-h/PrimeSequence%25255B7%25255D.png&quot;&gt;&lt;img alt=&quot;PrimeSequence&quot; border=&quot;0&quot; height=&quot;220&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsFPc_Dnk_djjQiahoPWj1dskkehucJxOn4EOc-jEOQxB9joUUe0TSJ65rN8hlPmOsav2KZI79LS5edQMpgAx3KcMtRchy4Ltwadb8_WFRoEVDv3l3a2ADS84Nz5k9mXUddp9eQwEep8WN/?imgmax=800&quot; style=&quot;border-width: 0px; display: inline;&quot; title=&quot;PrimeSequence&quot; width=&quot;617&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;Compile the project and add a reference from the C# project to the F# project.&lt;br /&gt;
&lt;br /&gt;Next step: the Model. We contact the UI designer and he sends us the following XAML: &lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;ItemsSource&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Binding&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot; &amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView.ItemTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;DataTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;/&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;/&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;/&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;

                &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;0&quot;  &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;SequenceNumber&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;1&quot;  &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;-&amp;gt;&quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;2&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;DataTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView.ItemTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;We past it in the Grid of the MainPage. Gridview is one of the Windows Store App controls that can display collections.&lt;br /&gt;
&lt;br /&gt;Next we update the MainPage code behind:&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;using &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Collections.ObjectModel;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;and&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;public sealed partial class &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MainPage &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Page
    &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;{
        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;private &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;ObservableCollection&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&amp;gt; Collection;
        
        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;MainPage()
        {
            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.InitializeComponent();

            Collection = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;ObservableCollection&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&amp;gt;()
                {
                    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;(1, 2),
                    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;(2, 3),
                    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;(3, 5),
                    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;(4, 7),
                    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;(5, 11)
                };

            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.DataContext = Collection;
        }&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;We have created an ObservableCollection class called Collection and added some elements so we can see the result of the binding.&lt;br /&gt;
&lt;br /&gt;F5:&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIqq0yheQ-QyPgJuiVc86Z7oa47WlTIkVMvfkn58zbLVgabao_xEAviK0VjixE1frPGWP6Cifh5kVSqc_HydLquy5e4zjmod4_H9nVaGGnZ-aT0Srx5-4371tXrcp84kgShxBKqvR-6fx-/s1600-h/PrimeSequenceWinRT1%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;PrimeSequenceWinRT1&quot; border=&quot;0&quot; height=&quot;308&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_Dgbje7j6KvFypSGTFS6KARBp8dPtSlrRNFBRD81BrN9Ax6bMWu5Xwt6xXjmaliew5ZfEvu9I_u7I7WDzOUHVV4X-MMg-vycSVBpPK09lAS6_7-bA6jwnL_Yg7KPMKCGDUYh6vmd-_mrS/?imgmax=800&quot; style=&quot;border-width: 0px; display: inline;&quot; title=&quot;PrimeSequenceWinRT1&quot; width=&quot;479&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;It works as expected but it does not look good.&lt;br /&gt;
&lt;br /&gt;So we contact our designer again. This is the code he sends us:&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Background&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;StaticResource &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;ApplicationPageBackgroundThemeBrush&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Primes&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Left&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Top&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;42&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Margin&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;80,40,0,0&quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;ItemListView&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;ItemsSource&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Binding&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Margin&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;80, 100, 80, 80&quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView.ItemsPanel&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ItemsPanelTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;WrapGrid &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ItemsPanelTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView.ItemsPanel&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView.ItemTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;DataTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;200&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;60&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Background&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Green&quot;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;60&quot;/&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;20&quot;/&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;120&quot;/&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;

                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;0&quot;  &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;SequenceNumber&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot;  &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Left&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Top&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;15&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Black&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Margin&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;5,5,5,5&quot; /&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;2&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;}&quot;  &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Left&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;Top&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;24&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;White&quot;
                        &lt;/span&gt;&lt;span style=&quot;background: white; color: red;&quot;&gt;Margin&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;=&quot;5,5,5,5&quot;/&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;DataTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView.ItemTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;GridView&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515;&quot;&gt;Grid&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;and the result looks like this (replace the XAML and press F5):&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Y5AVCqIdCWcfMNLLQoYl5FeTfVyVNej6qkJngB1RndJSMh5Z2TqwVthj1iRoqL8DqHkglQyGBAmcK5OhQy7l7HRZpkNKg91TY8rtViR4v7IThvWI8JsW94OK3geWL7U-lWewxBOplold/s1600-h/PrimeSequenceWinRT2%25255B6%25255D.png&quot;&gt;&lt;img alt=&quot;PrimeSequenceWinRT2&quot; border=&quot;0&quot; height=&quot;374&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMg0tu0d0_MgNHI2cwxYlC5e1V4mw05ot2nQOx-StzWWWMPAFI1rnAJjES4rVbsxoqwcP27KhgjpATWTCAS0bj7mc6opS2t-087iwaMvWz8uITfv2pP9yecWKDdecJmmYkM1cXdEaNTfmy/?imgmax=800&quot; style=&quot;border-width: 0px; display: inline;&quot; title=&quot;PrimeSequenceWinRT2&quot; width=&quot;336&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;We accept this design.&lt;br /&gt;
&lt;br /&gt;Remark: there are better ways to deal with design data in XAML: &lt;a href=&quot;http://weblogs.asp.net/thomaslebrun/archive/2009/05/04/wpf-mvvm-how-to-get-data-in-design-time.aspx&quot; target=&quot;_blank&quot;&gt;[WPF / MVVM] How to get data in “design time” ?&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;Now it is time to glue the Model and the View together, we will add the View Model code.&lt;br /&gt;
&lt;br /&gt;First we change the initialization of the Collection:&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;  Collection = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;ObservableCollection&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;MathLib&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;Element&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;and add a new F# file to the F# project called ViewModel.&lt;br /&gt;
&lt;br /&gt;We add the following code:&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;ViewModel
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Collections.ObjectModel
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;) =
    collection.Clear()
    MathLib.primeSequence |&amp;gt; Seq.iter collection.Add&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;Build the solution and add the following code to event handler &lt;span style=&quot;background: white; color: black;&quot;&gt;OnNavigatedTo&lt;/span&gt; of the MainPage:&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;protected override void &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;OnNavigatedTo(&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;NavigationEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e)
{
    &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;ViewModel&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.addElements(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.Collection);
}&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;F5 and the application never shows the Main Page:&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM6ODxcfwPqA64OBJdYzRToRVwaB_GA0f4dEUOGKcgHVtZ9y4kK4xAx2qbu3X_JnVfRzThTnoy0ghEfEgSEWDyW_Bf2-sHJDeRzhEm3QJXagb6-Wz1TPR_Ui-9c-wDnrc-x7hv0Pmjov84/s1600-h/screenshot_01292013_114516%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;screenshot_01292013_114516&quot; border=&quot;0&quot; height=&quot;398&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi85KBlkRS7QHkAIzvOp_WORR-5K5afd41W_JnL0TiC-uizAhk72ibJlqfm0ovGKKbHSuVfmBmrnZ4F55LDEnbj2Pw2hl_7we1xXAtuH8I_ns5ccG3myj_pPDMOgKXWDUSD-2C3C_lhGw9C/?imgmax=800&quot; style=&quot;border: 0px currentColor; display: inline;&quot; title=&quot;screenshot_01292013_114516&quot; width=&quot;684&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;When we reduce the number of elements to 100&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;) =
    collection.Clear()
    MathLib.primeSequence|&amp;gt; &lt;strong&gt;Seq.take 100&lt;/strong&gt; |&amp;gt; Seq.iter collection.Add&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;we get the expected result.&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpzU521FOMGdaiYEb10-7SA0Z7mogWvslmKL4jQcJIhYNT4WJkZT5cLs0A7nDesumxjohVQjL-EKHC-yVIoB1PVLtzH5ecEVaetXSImPiZxx2NO0mJdVpfYXbZD2FOSjcSLAHMAK2Vedza/s1600-h/screenshot_01292013_114929%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;screenshot_01292013_114929&quot; border=&quot;0&quot; height=&quot;398&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyOb-a-gjc_YYK-U_it8fVUeYOQnVrw6Trsob81_4QafT7wgTljYOgTEEixIukOYOcPUb35UXdBKETuBk5ElI0JygZih-8Aqfx0nOdtn8g1VTDh_Rd2_7fYHBsyC_cyyPacOKN9KDWcH-w/?imgmax=800&quot; style=&quot;border: 0px currentColor; display: inline;&quot; title=&quot;screenshot_01292013_114929&quot; width=&quot;683&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;This solution will not work when we want to display a very large number of primes.&lt;br /&gt;
&lt;br /&gt;So we go the async/await way again.&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;protected async override void &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;OnNavigatedTo(&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;NavigationEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e)
{
    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;await &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;ViewModel&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.addElementsTask(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.Collection);
}&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;and change the ViewModel&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;ViewModel
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Collections.ObjectModel&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Threading.Tasks
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;) =
    MathLib.primeSequence|&amp;gt; Seq.iter collection.Add

&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElementsTask(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;) =
     collection.Clear()&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;blockquote&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;Task.Factory.StartNew(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements collection);&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;br /&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;This time we get error messages:&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU18KFPo5tEu_Lu-en73RQHggQn7Zpc6yzGdo3mSKxhZgiHOZMbzK-maqu-_C6ySQqEJ3BK9WYSKZdS9UO9hKJUeGGpaG9tqkIzmIi8xvLyaUBoOd1QJv-dXMm9YSPSF0NvJWSsC6uWbgo/s1600-h/Error%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;Error&quot; border=&quot;0&quot; height=&quot;185&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGENkNVotM4RSOtmr8ESRjlMeRshfPLWYD66glVFKU8FJbDh4mX5Jz9jdIubuOvx9p0X-6XSf4PYpzNavHK15SAkydyn1NHWki6v-T5OLM9U0WQ9hoVPzezjynYHAJQY14hVyZswSAu9f8/?imgmax=800&quot; style=&quot;border: 0px currentColor; display: inline;&quot; title=&quot;Error&quot; width=&quot;584&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;The C# project needs a reference to the F# library. We will not go that way, we solve the issue by creating a Task of int and add a dummy return value.&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;ViewModel
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Collections.ObjectModel&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Threading.Tasks
&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;) = 
    MathLib.primeSequence |&amp;gt; Seq.iter collection.Add

&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElementsTask(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;) =
     collection.Clear()
     Task&amp;lt;int&amp;gt;.Factory.StartNew(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt;
                                &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection)
                                0)&lt;/span&gt;&lt;/pre&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;F5 again. This time we get an context exception.&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3QTnoV_v1waTGh81TzHC1b2oO2zebt9Yr08rsQEu0xzxmelHzl-Layxf3E3RUk5NqgskkBpQipLPKjINp735b2ubLZZxVrn9WNdn-PfXsojXGpLXNRi4eJHaNxzdlA3lG2XPIARADnabC/s1600-h/ContextException%25255B7%25255D.png&quot;&gt;&lt;img alt=&quot;ContextException&quot; border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOYV5pNcxtm3kpE4SGyUYyJz-4fQzKYCZWipuBPv1rOwH920UN_3p6Gjvb9CiXZ2jxUCAodTJe69Ft-0CJvi-xLAWuxVYjzCpDazB5KuA-XWYtSSfWVylSehNDEYDBG4KjjKvEJ9yXfPZV/?imgmax=800&quot; style=&quot;border: 0px currentColor; display: inline;&quot; title=&quot;ContextException&quot; width=&quot;597&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;So we add the context to the functions.&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;protected async override void &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;OnNavigatedTo(&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;NavigationEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e)
        {
            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;await &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;ViewModel&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.addElementsTask(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.Collection, System.Threading.&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af;&quot;&gt;SynchronizationContext&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;.Current);
        }&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;and&lt;br /&gt;
&lt;br /&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;ViewModel&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Collections.ObjectModel&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Threading&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;System.Threading.Tasks&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;, context:SynchronizationContext) =&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MathLib.primeSequence |&amp;gt; Seq.iter(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;context.Post((&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;collection.Add(x)) ,&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;))&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElementsTask(collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;, context:SynchronizationContext) =&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; collection.Clear()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Task&amp;lt;int&amp;gt;.Factory.StartNew(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElements(collection,context)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0)&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;and we get the desired result:&lt;br /&gt;
&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWZBMWE3O_RxuVSdO8UyxbSwPP9xzFCUWhBSsWMXr_U_D8eYPTwvIhcDS5gsaQx9w5kBa4EQNVOH7N-3hLO8xbfeZzGni5Emblnh5UNRJ67Htj0ThyphenhyphenNZBKzhq62sMG18jUyvrRfYVMTToI/s1600-h/screenshot_01292013_124616%25255B7%25255D.png&quot;&gt;&lt;img alt=&quot;screenshot_01292013_124616&quot; border=&quot;0&quot; height=&quot;368&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9QLLq3YYggwzqB9twYGarYjq3UqO57IIMFoamixRzqWVi1rWpY0Q-tH43k4LFmpPrOpArQNIv8kszNRZS6y4oG9fQw6k_cicqEDxj1yrWlFTrfHX7qOkLuXt1hPKr-K18Ptq5tXae2kC/?imgmax=800&quot; style=&quot;border: 0px currentColor; display: inline;&quot; title=&quot;screenshot_01292013_124616&quot; width=&quot;631&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;We end with two small remarks:&lt;br /&gt;
&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;
&lt;li&gt;In this post we used the ObservableCollection, this is a .NET solution. The WinRT way is to use &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/windows/apps/br226052(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;IObservableVector&amp;lt;T&amp;gt;&lt;/a&gt;.&lt;/li&gt;
&lt;br /&gt;
&lt;li&gt;We can replace &lt;span style=&quot;background: white; color: black;&quot;&gt;addElementsTask by&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;addElementsTaskMutable (collection:ObservableCollection&amp;lt;MathLib.Element&amp;gt;, synchronizationContext:SynchronizationContext) =
    collection.Clear()
    Task&amp;lt;int&amp;gt;.Factory.StartNew(
        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; 
        let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e = MathLib.Element(0,  1L)
        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;while true do
            &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;e &amp;lt;- MathLib.nextPrime e
            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;x = e  &lt;/span&gt;&lt;span style=&quot;background: white; color: green;&quot;&gt;//make the result immutable
            &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;synchronizationContext.Post((&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;collection.Add(x)) ,&lt;/span&gt;&lt;span style=&quot;background: white; color: blue;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;background: white; color: black;&quot;&gt;)
        0       
        )&lt;/span&gt;&lt;/pre&gt;
This seems to improve the performance of the application quit a lot.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/429451765613465411/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/429451765613465411' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/429451765613465411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/429451765613465411'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-4.html' title='Windows Store Apps with F# (part 4) : Collections'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsFPc_Dnk_djjQiahoPWj1dskkehucJxOn4EOc-jEOQxB9joUUe0TSJ65rN8hlPmOsav2KZI79LS5edQMpgAx3KcMtRchy4Ltwadb8_WFRoEVDv3l3a2ADS84Nz5k9mXUddp9eQwEep8WN/s72-c?imgmax=800" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-548632367076231207</id><published>2013-01-28T10:07:00.001+01:00</published><updated>2013-02-01T09:13:44.827+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Binding"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="MVVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows 8 Store App"/><category scheme="http://www.blogger.com/atom/ns#" term="WinRT"/><title type='text'>Windows Store Apps with F# (part 3) : Data Binding and MVVM</title><content type='html'>In this series of posts we investigate the interoperability between WinRT and F#. In the previous &lt;a href=&quot;http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-2.html&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; we solved some issues by adding input checking and async event handling. Our code still contained C# code. We can ride of some of the C# code by data binding.&lt;br&gt;Data binding connects XAML code directly with .NET objects. Let’s create a simple example. &lt;br&gt;Open the project we have created in part 1 and updated in part 2 and add a F# file called Process. We add the namespace MathLib and create an object Process.&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MathLib&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Process() =&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_output = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;output&quot;&lt;br&gt;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Output&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;get() = _output&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;set(v) =&lt;br&gt;            _output &amp;lt;- v&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;and rebuild the project so the Process object becomes available in the C# project.&lt;br&gt;&lt;br&gt;To the C# code of the MainPage we add a process variable, create a new Process object. We add it to the DataContext of the MainPage:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Process &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;process;&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MainPage()&lt;br&gt;{&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.InitializeComponent();&lt;br&gt;    process = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Process&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;();&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.DataContext = process;&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;and change the MainPage.xaml: Text=&quot;{Binding Output}&quot;&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.ColumnSpan&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot;  &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;result&quot; &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Style&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;StaticResource &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FSharp&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot; &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Output&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot;&lt;br&gt;            /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;F5 and this is the result.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwiOToAHW1a7fH1YvjGXYPlmGseXkdB-ge707z3K50TpYfz9BMMxDwbYKdicZuyQdWGKwWCEg07rZnFXV51t4Rjhy_wj5k7lK4tl_3_0U9mng8vAxt2ayvgtwl1NAut8CHsZbFoivsXqWZ/s1600-h/screenshot_01262013_1420463.png&quot;&gt;&lt;img title=&quot;screenshot_01262013_142046&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01262013_142046&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYA6gEK3nFfeUVqip_mlHW6YnHiE6cl1v6qlXYRQmy3er-D1NvdxzPBSNg5XbPtUZtNkf8A5TTvBKPfERwSLGMkZXZC69eBXPE054mX15WQHsGNnL1amyOnkFULL56NMlFzpHNDIJJ6Cip/?imgmax=800&quot; width=&quot;632&quot; height=&quot;368&quot;&gt;&lt;/a&gt; &lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;The initial value of the Process object (“output”) is shown at the location of the result TextBlock.&lt;br&gt;&lt;br&gt;Next we at an extra property to Process object.&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MathLib&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Process() =&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_input = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;input&quot;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_output = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;output&quot;&lt;br&gt;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Input&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;get() = _input&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;set(v) =&lt;br&gt;            _input &amp;lt;- v&lt;br&gt;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Output&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;get() = _output&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;set(v) =&lt;br&gt;            _output &amp;lt;- v&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;And add a Execute method.&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Execute() = &lt;br&gt;        &lt;span style=&quot;background: white; color: black&quot;&gt;x.Output &lt;/span&gt;&amp;lt;- _input |&amp;gt; MathLib.Wrapper.IsPrimeText&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;And change the XAML of the TextBox&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBox &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot;                  &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;inputValue&quot;                 &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Verdana&quot; &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;32&quot;&lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=Input, &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Mode&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=TwoWay}&quot;&lt;br&gt;            /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;We change the code of the event handler:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;private void &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;OnClick(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;object &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;sender, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;RoutedEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;e)&lt;br&gt;{&lt;br&gt;    process.Execute();&lt;br&gt;    result.Text = process.Output;&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;and test the result by entering “12” as input and click the button.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSmYqXczmx56-fnhlUcb67mp1_p0QRBisd7zYpUm8HmRBeNZjM3_N46D5YDS36_QgTZro8beT7hg_4WQi2xieVCWMc4h2uhHpytk0i_PwC_iw_XclXShsFBrr87PMNQ2WRl55zJoXkw075/s1600-h/screenshot_01262013_1512263.png&quot;&gt;&lt;img title=&quot;screenshot_01262013_151226&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01262013_151226&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQKmhDp-l12uuvBGPZRz-GyNlGGtfW1H5Se6jfBK8ZEsGamc8FoAnTmjhgLbXTluQgtGnDXiaCRW0IfepbZqE3rBQl-yUtevCeBYzeqoVXl-xOXuNFaAq9Bk9312eA_Sg9HuWQyz3_E6qs/?imgmax=800&quot; width=&quot;554&quot; height=&quot;323&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;So by adding “Mode=TwoWay” the input value of the TextBox is transferred back to the Input property of the Process object.&lt;br&gt;&lt;br&gt;Let’s change the event handler, let’s remove the last line:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;private void &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;OnClick(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;object &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;sender, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;RoutedEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;e)&lt;br&gt;{&lt;br&gt;    process.Execute();&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;and test again.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFvoKwDpf3IgIeZYwrlnKb_TRooMXTipyLuMVXFJLJBaFluPAVRE3LTxEoqCJtyTwRoRiZKlObfGLgOk2Tnd81UvNx_H7xNAr00aPpaVY4uttBRcxoblNyNetLv87wi83VFDak5dwFxT0h/s1600-h/screenshot_01262013_1514353.png&quot;&gt;&lt;img title=&quot;screenshot_01262013_151435&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01262013_151435&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYrHNkszIM8tTv6tYf3t_yUKIbdNndk_0Tkc8SPrAVC3CoQqulfJC6q8N48kdCGSrng4swHVx9_boLEcynCXqCJmjyHtylGXz_rE6pAdZsXMWpj7jbCeCC8EyLeIK3rCY5YcIM3Pizx1mC/?imgmax=800&quot; width=&quot;668&quot; height=&quot;389&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;This time the result is not updated. We have to notify the XAML that things have changed.&lt;br&gt;&lt;br&gt;We can tell the XAML that things have changed by implementing the INotifyPropertyChanged interface. This is a simple interface, it has one method: PropertyChanged.&lt;br&gt;&lt;br&gt;We could write this code ourselves, or we could leverage what is already available (&lt;a href=&quot;http://en.wikiquote.org/wiki/Isaac_Newton&quot; target=&quot;_blank&quot;&gt;standing on the shoulders of giants&lt;/a&gt;). So let’s enter &lt;a href=&quot;http://en.wikipedia.org/wiki/Model_View_ViewModel&quot; target=&quot;_blank&quot;&gt;MVVM&lt;/a&gt; (Model View ViewModel).&lt;br&gt;&lt;br&gt;There are several related architectural patterns &lt;strong&gt;MVP&lt;/strong&gt;, &lt;strong&gt;MVC&lt;/strong&gt;, &lt;strong&gt;MVVM&lt;/strong&gt;. They all prescribe the way separation of concerns is implemented a rich user interface application.&lt;br&gt;&lt;br&gt;So the main theme is separation of concerns. In the case of MVVM we have:&lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;ul&gt;&lt;br&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Model&lt;/strong&gt;. This is all the code that does not care about the presentation. It contains all code that is unaware of users interacting with the system, so we could create several ways of presenting the model to the user: WPF, Windows Store App, internet website, etc., in all cases the model stays the same. So the model could contain: &lt;br&gt;&lt;br /&gt;&lt;ul&gt;&lt;br&gt;&lt;br /&gt;&lt;li&gt;all business logic &lt;br&gt;&lt;br /&gt;&lt;li&gt;all persistence related logic&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;In our example the model is managed by a mathematician. He is the domain expert and knows everything about primes.&lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;View&lt;/strong&gt;. This is the presentation layer. It describes the look and feel of the application. The aim is to create declarative code like XAML and reduce the code in the code behind as much as possible. &lt;br&gt;In our example the view is managed by a UI designer. He has chosen&amp;nbsp; the red color and the font.&lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;View Model&lt;/strong&gt;. This is the bridge between the model and view. Imaging the model and view are already available. We know what it the App looks like and all business and persistence logic is created. All code required to make the application complete will be part of the View Model.&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;This is where we are right know in our example. To complete the application we have to create View Model code. We could write this code ourselves, or we could leverage what is already available.&lt;br&gt;&lt;br&gt;There are several MVVM frame works available: &lt;a href=&quot;http://www.japf.fr/2009/10/a-quick-tour-of-existing-mvvm-frameworks/&quot; target=&quot;_blank&quot;&gt;MVVVM Frameworks.&lt;/a&gt;&lt;br&gt;&lt;br&gt;Of course we go for the F# option: &lt;strong&gt;&lt;a href=&quot;https://github.com/dmohl/FSharpWpfMvvmTemplate&quot;&gt;FSharpWpfMvvmTemplate&lt;/a&gt;&lt;/strong&gt; by Dan Mohl. This template was not created with WinRT in mind, so we have to be careful.&lt;br&gt;&lt;br&gt;Create a new base class in the F# project called “ViewModelBase.fs” and copy the code for the template project:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: green&quot;&gt;//https://github.com/dmohl/FSharpWpfMvvmTemplate&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FSharpWpfMvvmTemplate.ViewModel&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows.Input&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.ComponentModel&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;ViewModelBase() =&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;propertyChangedEvent = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DelegateEvent&amp;lt;PropertyChangedEventHandler&amp;gt;()&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;INotifyPropertyChanged &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;[&amp;lt;CLIEvent&amp;gt;]&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.PropertyChanged = propertyChangedEvent.Publish&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.OnPropertyChanged propertyName = &lt;br&gt;        propertyChangedEvent.Trigger([| x; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;PropertyChangedEventArgs(propertyName) |])&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;And change the code of the Process class:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MathLib&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open  &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FSharpWpfMvvmTemplate.ViewModel&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Process() =&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;inherit &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;ViewModelBase()&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_input = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;input&quot;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let mutable &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_output = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;output&quot;&lt;br&gt;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Input&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;get() = _input&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;set(v) =&lt;br&gt;            _input &amp;lt;- v&lt;br&gt;            x.OnPropertyChanged(&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;Input&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;)&lt;br&gt;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Output&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;get() = _output&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;and &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;set(v) =&lt;br&gt;            _output &amp;lt;- v&lt;br&gt;            x.OnPropertyChanged(&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;Output&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;)&lt;br&gt;&lt;br&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Execute() =&lt;br&gt;        x.Output &amp;lt;- MathLib.Wrapper.IsPrimeText _input&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;we derive the Process class from the &lt;span style=&quot;background: white; color: black&quot;&gt;ViewModelBase&lt;/span&gt; class and raise the OnPropertyChanged event when the value of one of the properties is changed.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1rVPFnfW73fc22UO7oHjquG-YMmL_geWJgXMFRnqQzaFAv6MuDa1C7UkDAgNbttbQ5oGfHhGpXWtDRmasS8EVyFAHlS1Wbpqo16t0BhbrenAEb0YngSuCzqX-LFi5yThED-k8ERbdsTY4/s1600-h/ProcessUp4.png&quot;&gt;&lt;img title=&quot;ProcessUp&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ProcessUp&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJgRVIKeezshoRpiP7iZlrOKdoI4AOfln5UmtB24hg_spF1IsT83Gd0GF33XZLSIwRF5NC7I3Hb9YU07mflaB_Pfmh1l0iHPrrZbsknTksVVjwOgzLN3U50UcZHNFzGuwPRTwi0-7tKFSp/?imgmax=800&quot; width=&quot;696&quot; height=&quot;394&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;We have to move the Process file to it’s correct place in the project to let it compile:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp3UNJ8WE0KGyjt1I3j_IuOkBUqylarhimxMfrzJ2xpFAhJBsdKhjAmn03eW2JI81cLmEVUyPv833f5Oe5eeKn5I6MZr_VgltrrILAn2gzEvcJuZzyBrd1msoNzhlRoCa_E_V5AxdjsxVj/s1600-h/ProcessDown3.png&quot;&gt;&lt;img title=&quot;ProcessDown&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ProcessDown&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Z5jS5qt5YLr2uj_gtX8kNRhkCAGGly6Ebl2PcIwmIO1aktWe0gMxeg9g5W5Jj-_S6gxTblD-EqZOQ2ipqYgK7cgveRZ0Pq1IgmudlB0NT8mXyB06WN-A1sHj0I0PddvO5A9Jjzc4TM4_/?imgmax=800&quot; width=&quot;696&quot; height=&quot;389&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;The result:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxR_S8kmvkW-3elK8ndiz8G8qe3ndR1ej1yih_kZWZ4TF68zWrKL9oHFZ96Bsfu8Sfp7Pxmdv9xd1e37IV6_7r_czX5VcpAjbYjsWe3Mn5udvrInmzDuCQiidjHN6AaVlG1z3o-NY_2nIE/s1600-h/screenshot_01272013_1155443.png&quot;&gt;&lt;img title=&quot;screenshot_01272013_115544&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01272013_115544&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA_7W-PSEwL4yo3k524M340SSzoOIGJcLG67o_ImL9MLYhZ0wjYdPxbgmHDb2QLeEDcAKxfDe8A-OF4ahU-4l-P8nqIa30Zl4IYXmO8H8ymmYU__hxUCmpjVikrYrKqObKgIG0h98eYozq/?imgmax=800&quot; width=&quot;678&quot; height=&quot;395&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;So it works. We have now two issues to solve:&lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;ol&gt;&lt;br&gt;&lt;br /&gt;&lt;li&gt;The code we created can not deal with log running calculations. Just enter 756771235126757131 and the UI freezes. &lt;br&gt;&lt;br /&gt;&lt;li&gt;We still have an event handler, the button click. Is there a better way to deal with this so we can write the what happen after we click the button with F# code?&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;We solve the second issue first. Again MVVM comes to the rescue. We can bind a Command to the button. A Command is a class that implements the ICommand interface. We copy again from &lt;a href=&quot;https://github.com/dmohl/FSharpWpfMvvmTemplate&quot;&gt;&lt;strong&gt;FSharpWpfMvvmTemplate&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;. &lt;/strong&gt;Create a new F# file and call it RelayCommand and copy the code:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: green&quot;&gt;//https://github.com/dmohl/FSharpWpfMvvmTemplate&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;﻿&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;namespace &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;FSharpWpfMvvmTemplate.ViewModel&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Windows.Input&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.ComponentModel&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;RelayCommand (canExecute:(obj &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;bool), action:(obj &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;unit)) =&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;event = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DelegateEvent&amp;lt;EventHandler&amp;gt;()&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;ICommand &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;[&amp;lt;CLIEvent&amp;gt;]&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.CanExecuteChanged = event.Publish&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.CanExecute arg = canExecute(arg)&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Execute arg = action(arg)&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;Replace the Execute method Process file by the ExecuteCommand:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ExcecuteCommand = &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;RelayCommand ((&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;canExecute &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; true&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;), &lt;br&gt;                (&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;action &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;br&gt;                    &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.Output &amp;lt;- x.Input |&amp;gt; Wrapper.IsPrimeText ))&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;Remove the event handler in the code behind and change the XAML of the button into:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Button &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;2&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.ColumnSpan&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot; &lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Content&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Is it a prime?&quot;&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;calculate&quot; &lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;#FFE68484&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Verdana&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;32&quot; &lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Command&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Binding &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;ExcecuteCommand&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;We deleted the Click handler and add the binding of the Command.&lt;br&gt;&lt;br&gt;F5 and the app works the way it worked, this time without the C# event handler and with F# Command.&lt;br&gt;&lt;br&gt;To solve the first issue, dealing with long running calculations we change the code of the Command:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ExcecuteCommand = &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;RelayCommand ((&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;canExecute &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; true&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;), &lt;br&gt;                (&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;action &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;br&gt;                    let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;task = x.Input |&amp;gt; Wrapper.IsPrimeTask &lt;br&gt;                    x.Output &amp;lt;- task.Result))&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;in this case task wrapper to perform the code asynchronous.&lt;br&gt;&lt;br&gt;So everything works fine again.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi37i3I0UL5F3nxPDChaWuTQsyr5kC9VcQz5LJIlnraICAm4EZZ4c-2raJVSjUki1UBsWvgfdrP6ap6mdZubJQEHfXPKQHQS1qjzzejW7yrLw__MC-dUezU0X4zbffLUTppKb1SUmpvE51p/s1600-h/screenshot_01282013_091535%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;screenshot_01282013_091535&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01282013_091535&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIAQrUH7RQZeoCwLEqTCU_OIGXL4xXjhWMcDNYdVRrymyORChmD2s3GqHFK5clPikUvHZqHLXInCIpMCPtpwC-BYWgojSDUye8HfFamaMTUzzw6MZxmFqgVpILO6lBHhhbmeaDa3f90S5o/?imgmax=800&quot; width=&quot;591&quot; height=&quot;344&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;Let’s end with two remarks, the first is related with MVVM, the second with F# async.&lt;br&gt;&lt;br&gt;From our solution it is not clear how we dealt with separation of concerns.&lt;br&gt;&lt;br&gt;In our case we have a very small model, it contains just the IsPrime function. The View is the C# project and so the remaining F# code has to be the View Model: the wrappers, the Process class, the ViewModelBase and the RelayCommand are all part of the glue we needed to make the IsPrime function available for the user interface. In a real world project we have to make the structure explicate.&lt;br&gt;&lt;br&gt;In stead of using a Task we could use the F# async workflow. So let’s replace the ExecuteCommand by&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.ExcecuteCommand = &lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;RelayCommand ((&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;canExecute &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; true&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;), &lt;br&gt;                 (&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;action &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt;&lt;br&gt;                    let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;execute = &lt;br&gt;                        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;async &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;{ &lt;br&gt;                            x.Output &amp;lt;-Wrapper.IsPrimeText(x.Input)&lt;br&gt;                         }&lt;br&gt;                    execute |&amp;gt; Async.Start&lt;br&gt;                        ))&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;F5 and enter a value un the TextBox. We get an exception:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWffHFqQLkXSmMCAgcGVfCnd98U1th0dBk7P6CWVA7oARZZsnd17SRml9FaLqvQAR1m9RReiCPD47QQOW367O0-TElGfu-2an3-3v66BcfjZJsr_iy_pOXzS4gtUTETBXOCQjr5pz_Z9XG/s1600-h/Exeption%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;Exeption&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Exeption&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOW-YpyoML32nNtmZjLfHiXNrhvXCFqc1fh7zSRvV5rEVj0pZcaLTmVDPNvQCx_v-JB3-pjtcuExpgEAk0_OgKftqULsT8AyFIH74DufapqL6BVHmqVd2SIZfzy_1OdQYyCfwuH0b1icAN/?imgmax=800&quot; width=&quot;790&quot; height=&quot;208&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;The Dutch inner exception message tell us that we used the wrong thread to update the UI.&lt;br&gt;&lt;br&gt;We can fix this changing the ViewModelBase. We capture the context at initialization and Post at the context.&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;ViewModelBase() =&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: green&quot;&gt;//capture the context of the UI&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;context = System.Threading.SynchronizationContext.Current&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;propertyChangedEvent = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;DelegateEvent&amp;lt;PropertyChangedEventHandler&amp;gt;()&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;interface &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;INotifyPropertyChanged &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;with&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;[&amp;lt;CLIEvent&amp;gt;]&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.PropertyChanged = propertyChangedEvent.Publish&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;member &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x.OnPropertyChanged propertyName = &lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: green&quot;&gt;//Post at the right thread&lt;br&gt;        &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;context.Post(( &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;propertyChangedEvent.Trigger([| x; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;PropertyChangedEventArgs(propertyName) |])), &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;After the fix everything works fine again.&lt;/span&gt;&lt;br&gt;&lt;br&gt;The &lt;a href=&quot;http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-4.html&quot; target=&quot;_blank&quot;&gt;next post&lt;/a&gt; we discuss dealing with collections from a XAML F# perspective.&lt;br /&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/548632367076231207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/548632367076231207' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/548632367076231207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/548632367076231207'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-3-data.html' title='Windows Store Apps with F# (part 3) : Data Binding and MVVM'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYA6gEK3nFfeUVqip_mlHW6YnHiE6cl1v6qlXYRQmy3er-D1NvdxzPBSNg5XbPtUZtNkf8A5TTvBKPfERwSLGMkZXZC69eBXPE054mX15WQHsGNnL1amyOnkFULL56NMlFzpHNDIJJ6Cip/s72-c?imgmax=800" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-7725874304301565376</id><published>2013-01-24T16:35:00.001+01:00</published><updated>2013-02-01T09:22:15.533+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="async/await"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows 8 Store App"/><category scheme="http://www.blogger.com/atom/ns#" term="WinRT"/><title type='text'>Windows Store Apps with F# (part 2) : async/await</title><content type='html'>&lt;br&gt;In my last &lt;a href=&quot;http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-1-make.html&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; we created an windows apps and discussed the F# and C#/XAML interoperability. We discovered two issue:&lt;br&gt; &lt;ol&gt; &lt;li&gt;Long running calculations made the UI frees.  &lt;li&gt;The improper handling of the input made the app crash. &lt;/li&gt;&lt;/ol&gt;The way we deal with issues is an architectural decision. One can choose to have a slim F# library. The only responsibility is to handle the business logic, nothing else. In our case this is a math library. There is nothing wrong with decision, the other concerns are handled at the C#/XAML site by C# developers and XAML designers. We could resolve the first issue by wrapping the calculation in a task and await it. We could solve the input issues by writing a handler that will handle TextBox TextChanged&amp;nbsp; event. &lt;br&gt;If this is your decision the post ends here.&lt;br&gt;Or we could decide to minimize the C# code and solve all issues at the F# site. That is the way we will continue.&lt;br&gt;We start by where we left last time.&lt;br&gt;We first fix the second issue.&lt;br&gt;We delete in the MainPage XAML the last two TextBlocks and add a new one:&lt;br&gt;&lt;pre&gt;&lt;pre style=&quot;font-size: 12px; font-family: consolas,&#39;Courier New&#39;,courier,monospace; margin: 0em; width: 100%; background-color: white&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon&quot;&gt;TextBlock&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;Grid&lt;/span&gt;.&lt;span style=&quot;color: red&quot;&gt;Row&lt;/span&gt;=&lt;span style=&quot;color: blue&quot;&gt;&quot;3&quot;&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;Grid&lt;/span&gt;.&lt;span style=&quot;color: red&quot;&gt;Column&lt;/span&gt;=&lt;span style=&quot;color: blue&quot;&gt;&quot;1&quot;&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;Grid&lt;/span&gt;.&lt;span style=&quot;color: red&quot;&gt;ColumnSpan&lt;/span&gt;=&lt;span style=&quot;color: blue&quot;&gt;&quot;3&quot;&lt;/span&gt;  &lt;span style=&quot;color: red&quot;&gt;x&lt;/span&gt;:&lt;span style=&quot;color: red&quot;&gt;Name&lt;/span&gt;=&lt;span style=&quot;color: blue&quot;&gt;&quot;result&quot;&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;Style&lt;/span&gt;=&lt;span style=&quot;color: blue&quot;&gt;&quot;{StaticResource FSharp}&quot;&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br&gt;and add a text wrapper function to a new F# file called Wrapper.&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MathLib.Wrapper&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;IsPrimeText text = &lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;success, number = Int64.TryParse(text)&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;success &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;then &lt;br&gt;        if &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;Prime.IsPrime number &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;then&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;number.ToString() + &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot; is a prime number&quot;&lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;else&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;number.ToString() + &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot; is not a prime number&quot;&lt;br&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;else&lt;br&gt;            &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;text + &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot; is not a valid number&quot;&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;Now we can change the OnClick event handler in &lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;private void &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;OnClick(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;object &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;sender, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;RoutedEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;e)&lt;br&gt;{&lt;br&gt;    result.Text = &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Wrapper&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.IsPrimeText(inputValue.Text);&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;All the code to handle the text input and displaying the result are now in the wrapper. Text input does not crash the app.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuRlnLOgbfXbZEAVi3iI7ucibxX87Di3bKn411UfVgUgnLNr_C7FQZEkrJLfnHbzAE2DhVls4bPxw0bdqG6hFPdu4Rx7_mmKPvaxtskucGi4MUR-2tRHzlgbG573uyolJe2NCZMSc2HnR1/s1600-h/screenshot_01242013_115705%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;screenshot_01242013_115705&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01242013_115705&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinvwCp4ADN31IzYrgNyrLhs1qg8OaBbtToxV8Mu9iq_JUu3_F-j32qlDqIVRqscrM1X7Bomvy9bq56KcjDbaVWJqTDyZJydqdVLY20ViDN540miJyO1eJQn5_dfyM4UIdGUB-c-x7-h9Ut/?imgmax=800&quot; width=&quot;583&quot; height=&quot;340&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;In a real project we could put more logic to del with input in the wrapper functions.&lt;br&gt;&lt;br&gt;Next we have to deal with long running calculations. The new C# way is to use async/await. so we add async to the OnClick handler. We get a warning.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFZLy4mbV13bQoTFqW83ZMaJ7e4aZY0VzcxMZu0lOZ-4aesjsmzJgSDgktcoNbEOIaHQmOz-sbbzL5LH2CwYliDP_7Y0JLvUZo-KkQqj4oIKMUICUsIVVv7kDhjYbtNX4Hd6Ljhjys2OL1/s1600-h/Warning%25255B7%25255D.png&quot;&gt;&lt;img title=&quot;Warning&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Warning&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTO7bQZJLoF-BNnX3JRKgWyofsUtrwHjL_1bTXRufh-glnVtQbJpviNcHOqV54qvTt4AoPijCVgF8mbz0JbLAgwfdtV0Z5gwVUl8lgplJr1L56eh21A3Aryuwr7Cn2eagm9C4v-e_iZnUb/?imgmax=800&quot; width=&quot;639&quot; height=&quot;405&quot;&gt;&lt;/a&gt; &lt;br&gt;The warning tells us that we need to await something, and this should be a Task.&lt;br&gt;&lt;br&gt;So we create a second F# wrapper:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;open &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;System.Threading.Tasks&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;IsPrimeTask text =&lt;br&gt;    Task&amp;lt;string&amp;gt;.Factory.StartNew(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;_ &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;IsPrimeText text)&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;And call this function with await: &lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;private async void &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;OnClick(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;object &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;sender, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;RoutedEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;e)&lt;br&gt;{&lt;br&gt;    result.Text = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;start&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;;&lt;br&gt;    result.Text = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;await &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Wrapper&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.IsPrimeTask(inputValue.Text);&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;When we start the application and check 756771235126757131.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1inIQqZv0Ub7F2RkWP6Mn6L4nzo6mH6VMg_NQ_WzEaPsFx_zW5ZdOKXDQlQwj_mySsJE80rKQ9cPSUmJ0IvIay4oG3jUWhAo2RC29YjiYCax-2ylHYC-jLlj0pb97trdZCObwB5UeKc0s/s1600-h/screenshot_01242013_121614%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;screenshot_01242013_121614&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01242013_121614&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipobrxpxEX4dE4wbJ7sSScV-pwjcU4k41zp-CzhtR1soNLjvvxvlTqCDWbZeE39SePbkA3b29OhLyY1L7CIFoQO6zsBBaXJrtVx0T_qsIUvWZOE6zmIaZu3EjLhwu9qK2VKoT_hBEucAzi/?imgmax=800&quot; width=&quot;602&quot; height=&quot;351&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;The task is started and we can still update the UI. So the issues are solved.&lt;br&gt;&lt;br&gt;Remark: This works because it is .NET interoperability. One should use the WinRT the&amp;nbsp; interface&amp;nbsp; &lt;span style=&quot;background: white; color: #2b91af&quot;&gt;IAsyncOperation&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt;.&lt;/span&gt;&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;private async void &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;OnClick(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;object &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;sender, &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;RoutedEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;e)&lt;br&gt;{&lt;br&gt;    result.Text = &lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;&quot;start&quot;&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;;&lt;br&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;IAsyncOperation&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt; operation = &lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Wrapper&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.IsPrimeTask(inputValue.Text).AsAsyncOperation&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;&lt;br&gt;    result.Text = &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;await &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;operation;&lt;br&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;This interface does not seem to be available in the F# library. Fortunately we can not reference a F# Portable Library in a JavaScript App:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJCA1Z65FDtvo1MpJz4zJqIEN4rSyYKfCJ7nv_lNbb-g_4cD8xA6ORPaMRxMUHB7HFmLUmyprjK-OYWMh9IQt3lMwYyZYeemHQrHDAhThad7j8gdLQZvPJbWc-dG5gCKmabnX7Tksc7wQA/s1600-h/Html_FSharp%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;Html_FSharp&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Html_FSharp&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG22HBFg8t25x7Puuvy1UsuVMZL88uy_eGkOCFOazy_dLWMEYTq1PbA41WQbj_wKn09Se30MkK8-a8GolCKQO3l3XUXXm5oK7wBt3T5lSdRe22oMOPIedLytHf_Yc8puQDdJdUTb_6GaLz/?imgmax=800&quot; width=&quot;823&quot; height=&quot;410&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;So this is not an issue at the moment.&lt;br&gt;&lt;br&gt;Next time we will look for ways to get ride op the event handling code by looking at &lt;a href=&quot;http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-3-data.html&quot; target=&quot;_blank&quot;&gt;data binding and MVVM&lt;/a&gt;.  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/7725874304301565376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/7725874304301565376' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7725874304301565376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7725874304301565376'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-2.html' title='Windows Store Apps with F# (part 2) : async/await'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinvwCp4ADN31IzYrgNyrLhs1qg8OaBbtToxV8Mu9iq_JUu3_F-j32qlDqIVRqscrM1X7Bomvy9bq56KcjDbaVWJqTDyZJydqdVLY20ViDN540miJyO1eJQn5_dfyM4UIdGUB-c-x7-h9Ut/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-4539665058457488055</id><published>2013-01-23T20:32:00.001+01:00</published><updated>2013-02-01T09:12:22.289+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows 8 Store App"/><category scheme="http://www.blogger.com/atom/ns#" term="WinRT"/><title type='text'>Windows Store Apps with F# (part 1) : Make things as simple as possible, but not simpler.</title><content type='html'>&lt;br&gt;During the initial phase of the Windows 8 beta period it was not possible to integrate F# code in a Windows 8 store app. After the final release of Visual Studio 2012 it is possible to create hybrid projects. In this series of posts I want to show you some of the projects I use to experiment with F# and Windows App Store integration.&lt;br&gt;I will focus on the interoperability and assume that you are able to find resources to learn the details of XAML, Windows 8 store apps and F#.&lt;br&gt; &lt;h3&gt;&lt;/h3&gt;In the first example we create a simple solution and just add some F# code.&lt;br&gt;The F# code will determine if a number is a prime number. The App UI should have a text box to enter a value, a button to start the check and a text block to display the result.&lt;br&gt;We start by creating a blank windows store app:&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglYaM8rN-RY9M7nD5Rw_jSFwKI743sivzziWAqdktMPLJRVDMxpHnlUneO4rrd9_wyayL5jDVzUxXw6LHwshp_ClUf1X2TLSrloHEKGGPlqE-pAfFsswTwDpWF5YI0GIjayxmeB1RqQnt2/s1600-h/CreateProject3.png&quot;&gt;&lt;img title=&quot;CreateProject&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;CreateProject&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgxfNLTgiYvP7pWNro96pw0kPUIYAo2KL1EMB0c9HPKfzsWwvIwsoxBlAusqiNcrFPpWyOQIGePJvQN70wfhKqpUOGlB-efKaA3YuUPQtM_abrhsbOrNZitROGQTNoEeg3vdtcF1qpZZTq/?imgmax=800&quot; width=&quot;574&quot; height=&quot;405&quot;&gt;&lt;/a&gt; &lt;br&gt;Open the created main page&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3K2npPJXsH1QMImc3SeUldyuFncykx4WbIAYzLkas-TxeJQFFeMoc2AJyLxTvddv9v2z5XYMGqjJSb4vFPfl7TEL6tFuHF44SkuCmhXiqePRz-AzajxQM3zaq2fKz4kHkofGC2ZYjkbG9/s1600-h/MainPage2.png&quot;&gt;&lt;img title=&quot;MainPage&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;MainPage&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3vzFD7_HCthS8vpqgy8cCS5yMSYI10-Q2r-k7DKHNeWJ-83V33t9O06OyNg_r6YciB07K4crOKw6E3WvPO5INEftZ7O9G31sqKDjEM1pKVcz5rMzhnrGS18CN_YUKYvGtWT_JIewGcAgp/?imgmax=800&quot; width=&quot;244&quot; height=&quot;86&quot;&gt;&lt;/a&gt; &lt;br&gt;and start designing the layout of the page.&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Page.Resources&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Style &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Key&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;FSharp&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;TargetType&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;TextBlock&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;BasedOn&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;StaticResource &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;BasicTextStyle&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot;&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Setter &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Property&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;FontFamily&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Verdana&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Setter &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Property&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;FontSize&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;32&quot;/&amp;gt;&lt;br&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Style&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Page.Resources&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;Next we change the color of the grid and add some columns and rows:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Background&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;#FF8F0A0A&quot;&amp;gt;&lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;10*&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;200&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;100&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;300&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;ColumnDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Width&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;20*&quot;/&amp;gt;&lt;br&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;RowDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;10*&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;RowDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;50&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;RowDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;100&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;RowDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;50&quot;/&amp;gt;&lt;br&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;RowDefinition &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Height&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;20*&quot;/&amp;gt;&lt;br&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;And finally add the controls to the grid:&lt;br&gt;&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot;&lt;br&gt;                   &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Input value:&quot; &lt;br&gt;                   &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Style&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;StaticResource &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FSharp&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot;/&amp;gt;&lt;br&gt;&lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBox &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot; &lt;br&gt;                 &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;inputValue&quot; &lt;br&gt;                 &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Verdana&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;32&quot; /&amp;gt;&lt;br&gt;&lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Button &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;2&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.ColumnSpan&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Content&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Is it a prime?&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;calculate&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;#FFE68484&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Verdana&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;32&quot;/&amp;gt;&lt;br&gt;        &lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot;&lt;br&gt;                   &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Result:&quot;&lt;br&gt;                   &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Style&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;StaticResource &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FSharp&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot;/&amp;gt;&lt;br&gt;        &lt;br&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;TextBlock &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot;&lt;br&gt;                   &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;result&quot;&lt;br&gt;                   &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Style&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;{&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;StaticResource &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FSharp&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;}&quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;This is page in de designer:&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTBgN1hs5sk3EQ1LfVayaQxfparl2XVAf3vlAn7O2y0lHitNsn37FmGKScjGYkNQam7RIWUsL8z-tfduoI5TvKioaoILKgMSnK2nABU1uwxfxGzIkzLTmBzMIEhdomAyoqu66gVY9EPlFq/s1600-h/Designer4.png&quot;&gt;&lt;img title=&quot;Designer&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;Designer&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjq72LEO77tDivDR92O6kBNPEISKloKo8qeBchjEPoUkWrV5ODvSFtcyYQWQiAIiaJIPd20vMnYszldBOHvjRFhRQ94gXxOLuOvbppEBojqRK-FXU9DZgWfqpYDznBMC5bbGg0nNSJl77hv/?imgmax=800&quot; width=&quot;638&quot; height=&quot;549&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;Now is time to add the F# code. We add an F# Portable Library call “MathLib” to the solution.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4xkpT0q3x-EOI6N9H1sMfNqRt95k6X_KJr__2Go2zaWpzEO8XlTZ-E7krAFBX8VkR9tHHRMcM6zbMxLfpMlH0_bn2YawCAByxG8TbilDzScHIRg3OgZt5rAgGY8vHnIksWatqiOAFpfSv/s1600-h/FSharpProject%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;FSharpProject&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;FSharpProject&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKhEQMT-2oM4dfumFLpB9JMW6p_B7fzxY-lg2RjwoSsYttf38KHIius_XrJw5vh5LNrVQH93hMQaPTVUVbQLIChUnjzxS0LaZN4C8ouzqK673jZBdFTIM1mY-P1NMw0H7H793OBM4Idi5C/?imgmax=800&quot; width=&quot;650&quot; height=&quot;461&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;Rename PortableLibrary1 to Lib and delete the Script file.&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipGsBDEpecAAVfRnOS_ctpLJE4IsGx5L_LOLfVFsnpZq7igYiMTvM64GVwpKbzMig80AmqliD55a06Pbf458COegtkpyK-irHHXBZJL2XzHJGSSDYX-zgGEvvMSpKx3Kvk2Y0c20e51h14/s1600-h/FSharpProject2%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;FSharpProject2&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;FSharpProject2&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjudj3khdvsew9nDX8bfQzUxkUh-On5MOSN2n6e3LC2D5EZk38ivfo2czYZrgTZPrpBKBYJrNb43vCCjjZ6UF7MinTckbH40h4iUEx5uvI6lRqKiP5o7RHWfr7z5icl9FHngu7awYzm5Xz7/?imgmax=800&quot; width=&quot;459&quot; height=&quot;217&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;And add the F# code to the Lib file:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;module &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;MathLib.Prime&lt;br&gt;&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;IsPrime n =&lt;br&gt;     &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;n &amp;lt; 2L &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;then&lt;br&gt;            false&lt;br&gt;        else&lt;br&gt;            seq &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;{ 2L .. n - 1L}&lt;br&gt;            |&amp;gt; Seq.exists(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;fun &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;n % x = 0L)&lt;br&gt;            |&amp;gt; not&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;This is not the most sophisticated prime check but it will do for our projects.&lt;br&gt;&lt;br&gt;We have created a module we can use MathLib is the namespace, Prime is a static class and IsPrime is a static function. &lt;br&gt;&lt;br&gt;The code i in line with the definition of a &lt;a href=&quot;http://en.wikipedia.org/wiki/Prime_number&quot; target=&quot;_blank&quot;&gt;prime number&lt;/a&gt;: A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.&lt;br&gt;&lt;br&gt;Now we have to create interoperability. We add a reference to the MathLib project:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDptgAUJy2Rfleof-DQsxgmB39vrwvj0KZxxbReXVWm6mkik_RFPhlc30ZcxiG5Gf6MrhDINozzbMFMrbjIJip9JizkrrH3Wy6JG4CE6TNJOlXmTP_M5Ie6SW8iWzOmu_z_Ey6tBIDDWen/s1600-h/AddReference%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;AddReference&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;AddReference&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs5Zr4VToCXwJ2F3OwHWrwT9ykR0KUV2gpEypTWeS0hdmLwn9mvFHTko88kgc6teaacupCf5genyTHKey0QMJCY4ifOOkQpoYzv04bmW2scDhcTpnGa00D55UghDKqeEg1Opl4hoOJARS9/?imgmax=800&quot; width=&quot;622&quot; height=&quot;338&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;and build the solution. This will make the meta data of the MathLib project available for the&amp;nbsp; WinRTFSharpSimple project.&lt;br&gt;&lt;br&gt;Next we create add a button click event:&lt;br&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;background: white; color: black&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: white; color: #a31515&quot;&gt;Button &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Row&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;2&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.Column&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;1&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Grid.ColumnSpan&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;3&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Content&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Is it a prime?&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;calculate&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;HorizontalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;VerticalAlignment&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Center&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Foreground&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;#FFE68484&quot;&lt;br&gt;                &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontFamily&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;Verdana&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;32&quot; &lt;/span&gt;&lt;span style=&quot;background: white; color: red&quot;&gt;Click&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;=&quot;OnClick&quot;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;and add an handler at the code behind:&lt;br&gt;&lt;br&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;private void&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;OnClick(&lt;/span&gt;&lt;span style=&quot;background: white; color: blue&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;sender,&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;RoutedEventArgs &lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;e)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result.Text =&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Prime&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.IsPrime(&lt;/span&gt;&lt;span style=&quot;background: white; color: #2b91af&quot;&gt;Convert&lt;/span&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;.ToInt64(inputValue.Text)).ToString();&lt;br&gt;}&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style=&quot;background: white; color: black&quot;&gt;and add a namespace:&lt;/span&gt;&lt;br&gt;&lt;a href=&quot;http://11011.net/software/vspaste&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis-Zj5FAk4qkXJnrVb9CrPqVcef0aNym1o9yoYVIkprzr6q4pYp092VgTwCcssORIlf-3rJ5DL5s9cQvlma9HfdV9DbtoLPoa87j9kusRKdI17pct6KWbMl9-iowzmK05CgJdnf2mWChDe/s1600-h/OnClick%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;OnClick&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;OnClick&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhExmH7-yeJp3xNksIKKgV55Rr8-mKCs7lFhfvqUuCsP7jUdQyoi7r2kaISwI4xGf0nx2lq05BJ9KLDPj3cOAErfn185L9hf-LILlxch5LbT0Hzm4Y_UjDN5iqZC4oGiEvmLiZqO1jH1VXN/?imgmax=800&quot; width=&quot;575&quot; height=&quot;440&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;Time to test the app, F5:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFO37cexNRvS1k0hX6j3WBCSza8c5L5qV2PX5GHPDasD9zjzqlmKwWzQVjR6B44M-ZJvjM0h9X3OLr1oRhVX3AKpiWuK0YzDEJ-x9If_Wnn3G4InW8F_jexH8vhVTpd8VHA1fKWabX3eF6/s1600-h/screenshot_01232013_200741%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;screenshot_01232013_200741&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01232013_200741&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXYJDzV8D4L9WzJx2r2PiZIvq0WX6IUYBzqiBjEkw48-bNVb5nQz4WnajTL1FX1uTEYWzvI8X37wV6iDPvCIQY14MB5XcoplmoTgQzZWBYb5O8MC40vlGQ9axyXyKQJLwm2rI4QKrbJnwz/?imgmax=800&quot; width=&quot;491&quot; height=&quot;286&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAskAk4hrKcFqasbnJ-ePo4R3QmHzW5O9xWfFYxz9cbkB5wSaQg5UMV9N8kziaTHfHBw8SDXL4aIu6LKEcP8F4iVZ6WPShEoBGGOLfOGYW7jG1fIHpo-Wdf9MjsNfXeOTNQuOz4yevCzYR/s1600-h/screenshot_01232013_200947%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;screenshot_01232013_200947&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01232013_200947&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-n_prkoNXlxQtXM8Zscqg2nhmiM-hbyTf4SOU6s1MZPp3xKbFHaCypNPlCax8IqnHxemX0sdg2PgdO11BrP-IgiLRsnD9a0vJRDSGF_2ppyFKZppUOhlH3qyt44YoN8qZ5zlKt9wcYj4K/?imgmax=800&quot; width=&quot;499&quot; height=&quot;291&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;This looks fine.&lt;br&gt;&lt;br&gt;In case we enter 756771235126757131&lt;br&gt;&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTShXXLWe3P5noCVadpi9l_Z9JFYyw8aZgxl-3X2BR4upYGbs6KTjKIwjJJrSY7ky7NJZ8q8fyPo7y6YAU3JduG3UsmSDSdRxvsPjHkeZfJg9kYOaKPXQ85NHRsF1Z1EsFptXy-ybJniq4/s1600-h/screenshot_01232013_201358%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;screenshot_01232013_201358&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;screenshot_01232013_201358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgviQe3PvocVC-ucRsMh2DO7J8Qug8UFc50kZmEANFNbGSTrlZySc6zBIugnMupJv5SX5sf4Qb1VyRTPKhkyiy2eq85P1O-UjO0SkhsJt1O9hLdlDBJSmlT0xLWOZzz3t8wvfEYb6E8NXVV/?imgmax=800&quot; width=&quot;506&quot; height=&quot;295&quot;&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;the app freezes and we can not interact with the app (issue 1).&lt;br&gt;&lt;br&gt;In case we enter “abc” the app crashes (issue 2).&lt;br&gt;&lt;br&gt;How could we solve these issues?&lt;br&gt;&lt;br&gt;We can fix them at the C# site or we could fix the at F# site, both are possible. In the &lt;a href=&quot;http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-2.html&quot; target=&quot;_blank&quot;&gt;next post&lt;/a&gt; I will discuss a solution at the F# site.&lt;br /&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/4539665058457488055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/4539665058457488055' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/4539665058457488055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/4539665058457488055'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2013/01/windows-store-apps-with-f-part-1-make.html' title='Windows Store Apps with F# (part 1) : Make things as simple as possible, but not simpler.'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgxfNLTgiYvP7pWNro96pw0kPUIYAo2KL1EMB0c9HPKfzsWwvIwsoxBlAusqiNcrFPpWyOQIGePJvQN70wfhKqpUOGlB-efKaA3YuUPQtM_abrhsbOrNZitROGQTNoEeg3vdtcF1qpZZTq/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-6686284980736534826</id><published>2012-09-30T19:08:00.001+02:00</published><updated>2012-09-30T19:19:17.231+02:00</updated><title type='text'>Update of the F# reading list</title><content type='html'>&lt;p&gt;I have updated the F# list at &lt;a href=&quot;http://www.amazon.co.uk/F-and-functional-programming/lm/R14JYBWI11LWQS/ref=cm_lmt_srch_f_1_rsrsrs0&quot;&gt;http://www.amazon.co.uk/&lt;/a&gt;: &lt;a title=&quot;http://www.amazon.co.uk/F-and-functional-programming/lm/R14JYBWI11LWQS/ref=cm_srch_res_rpli_alt_3&quot; href=&quot;http://www.amazon.co.uk/F-and-functional-programming/lm/R14JYBWI11LWQS/ref=cm_srch_res_rpli_alt_3&quot;&gt;http://www.amazon.co.uk/F-and-functional-programming/lm/R14JYBWI11LWQS/ref=cm_srch_res_rpli_alt_3&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;There is two new books:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a title=&quot;F# for C# Developers&quot; href=&quot;http://www.amazon.com/F-C-Developers-Tao-Liu/dp/0735670269/ref=sr_1_1?ie=UTF8&amp;amp;qid=1349024844&amp;amp;sr=8-1&amp;amp;keywords=0735670269&quot; target=&quot;_blank&quot;&gt;F# for C# Developers&lt;/a&gt; by Tao Liu, an engineer on the F# team &lt;/li&gt; &lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Functional-Programming-F-Tomas-Petricek/dp/1439839980/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1349025272&amp;amp;sr=1-1&amp;amp;keywords=1439839980&quot; target=&quot;_blank&quot;&gt;Functional Programming in F#&lt;/a&gt; by &lt;a href=&quot;http://www.amazon.com/s/ref=ntt_athr_dp_sr_1?_encoding=UTF8&amp;amp;field-author=Tomas%20Petricek&amp;amp;ie=UTF8&amp;amp;search-alias=books&amp;amp;sort=relevancerank&quot;&gt;Tomas Petricek&lt;/a&gt; and &lt;a href=&quot;http://www.amazon.com/s/ref=ntt_athr_dp_sr_2?_encoding=UTF8&amp;amp;field-author=Jan%20Stoklasa&amp;amp;ie=UTF8&amp;amp;search-alias=books&amp;amp;sort=relevancerank&quot;&gt;Jan Stoklasa&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;and 2 updated versions:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Programming F# 3.0&amp;nbsp; by &lt;a href=&quot;http://www.amazon.com/s/ref=ntt_athr_dp_sr_1?_encoding=UTF8&amp;amp;field-author=Chris%20Smith&amp;amp;ie=UTF8&amp;amp;search-alias=books&amp;amp;sort=relevancerank&quot;&gt;Chris Smith&lt;/a&gt; (&lt;a title=&quot;http://www.amazon.com/Programming-F-3-0-Chris-Smith/dp/1449320295/ref=pd_sim_sbs_b_1&quot; href=&quot;http://www.amazon.com/Programming-F-3-0-Chris-Smith/dp/1449320295/ref=pd_sim_sbs_b_1&quot;&gt;http://www.amazon.com/Programming-F-3-0-Chris-Smith/dp/1449320295/ref=pd_sim_sbs_b_1&lt;/a&gt;)  &lt;li&gt;Expert F# 3.0 by &lt;a href=&quot;http://www.amazon.com/s/ref=ntt_athr_dp_sr_1?_encoding=UTF8&amp;amp;field-author=Don%20Syme&amp;amp;ie=UTF8&amp;amp;search-alias=books&amp;amp;sort=relevancerank&quot;&gt;Don Syme&lt;/a&gt;, &lt;a href=&quot;http://www.amazon.com/s/ref=ntt_athr_dp_sr_2?_encoding=UTF8&amp;amp;field-author=Adam%20Granicz&amp;amp;ie=UTF8&amp;amp;search-alias=books&amp;amp;sort=relevancerank&quot;&gt;Adam Granicz&lt;/a&gt;,&amp;nbsp; &lt;a href=&quot;http://www.amazon.com/s/ref=ntt_athr_dp_sr_3?_encoding=UTF8&amp;amp;field-author=Antonio%20Cisternino&amp;amp;ie=UTF8&amp;amp;search-alias=books&amp;amp;sort=relevancerank&quot;&gt;Antonio Cisternino&lt;/a&gt; (&lt;a title=&quot;http://www.amazon.com/Expert-F-3-0-Don-Syme/dp/1430246502/ref=pd_bxgy_b_img_y&quot; href=&quot;http://www.amazon.com/Expert-F-3-0-Don-Syme/dp/1430246502/ref=pd_bxgy_b_img_y&quot;&gt;http://www.amazon.com/Expert-F-3-0-Don-Syme/dp/1430246502/ref=pd_bxgy_b_img_y&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/6686284980736534826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/6686284980736534826' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6686284980736534826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6686284980736534826'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2012/09/update-of-f-reading-list.html' title='Update of the F# reading list'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-836289726067763152</id><published>2012-01-30T21:11:00.001+01:00</published><updated>2012-01-30T21:11:27.334+01:00</updated><title type='text'>Dutch article: Monads voor de .NET-ontwikkelaar is available at the SDN site</title><content type='html'>&lt;p&gt;I have written an article for the Dutch developer magazine of &lt;a href=&quot;http://www.sdn.nl/&quot;&gt;SDN&lt;/a&gt; (Magazine 111). It is titled: “Monads voor de .NET-ontwikkelaar”. It is now on line: &lt;a title=&quot;http://www.sdn.nl/SDN/Artikelen/tabid/58/view/View/ArticleID/3206/Monads-voor-de-NET-ontwikkelaar.aspx&quot; href=&quot;http://www.sdn.nl/SDN/Artikelen/tabid/58/view/View/ArticleID/3206/Monads-voor-de-NET-ontwikkelaar.aspx&quot;&gt;http://www.sdn.nl/SDN/Artikelen/tabid/58/view/View/ArticleID/3206/Monads-voor-de-NET-ontwikkelaar.aspx&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I have tried to read the English version by Google translate. This is not a very good translation. I do not recommend to read it this translation. The German version is even worse. It contains Engels words that are not part of the Dutch version.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/836289726067763152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/836289726067763152' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/836289726067763152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/836289726067763152'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2012/01/dutch-article-monads-voor-de-net.html' title='Dutch article: Monads voor de .NET-ontwikkelaar is available at the SDN site'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-4325619630158222964</id><published>2011-10-04T11:41:00.001+02:00</published><updated>2011-10-04T14:09:27.459+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="portable libraries"/><title type='text'>BCL Team Blog provides more information on code reuse (Portable Libraries part 4)</title><content type='html'>&lt;h1&gt;&lt;/h1&gt; &lt;p&gt;Today the BCL Team Blog addressed the issue of code reuse: &lt;a href=&quot;http://blogs.msdn.com/b/bclteam/archive/2011/10/03/porting-existing-net-code-to-metro-style-apps.aspx&quot; target=&quot;_blank&quot;&gt;Porting existing .NET code to Metro style apps&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&quot;One of the things we know people want to do is reuse existing .NET code but due to the constraints on Metro style apps it is not possible to directly reuse existing .NET class libraries nor is it always possible to simply recompile existing code. We realize this is going to be a pain point for many current .NET developers so we are working on a guide at the &lt;/em&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/windows/apps/br230302.aspx&quot;&gt;&lt;em&gt;.NET for Metro style apps overview page&lt;/em&gt;&lt;/a&gt;&lt;em&gt; which will assist developers in translating their existing .NET skill set into the Metro style apps world.”&lt;/em&gt;&lt;/p&gt; &lt;h2&gt;&lt;/h2&gt; &lt;p&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-790C&quot; target=&quot;_blank&quot;&gt;Bringing existing managed code into Metro style apps&lt;/a&gt;&quot; by Daniel Plaisted is a recommended resource. &lt;/p&gt; &lt;p&gt;&lt;iframe style=&quot;height: 416px; width: 649px&quot; src=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-790C/player?w=960&amp;amp;h=544&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;&lt;/p&gt; &lt;p&gt;Daniel ports a windows phone app to a Metro app. Most of presentation is mainly about porting the UI.&lt;/p&gt; &lt;p&gt;Some slides from the presentation:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg93H5NAFU9a4c9XrDRSiI8xNfi-5m9lo5NfyvjM0Y4hMTIk7AJHONM4Wnh17_oJpEqmTIuGhyMyF2eEikBaghZyakiFrrfp6DtUa1pdC6rnHxnn-iD4k3qttsSlHdYrWfQyolO14LK7sdH/s1600-h/move_code%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;move_code&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;move_code&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwSq6qovpurNZ80Lf2y34p8scwyHrucPvJt-1rvX06NglRwt8mOAHq-aGMgZfHJUASVcFDRaGfJS5c6a9sVnAtjA-BB4B_Td7oriD2QBF-jrDZUHv6c_sAWo7Ig3QD-A7-rAqpG5dZ_mRA/?imgmax=800&quot; width=&quot;583&quot; height=&quot;286&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_52vkhXf62CCIfb_qtaKKmBcpcqgGy49HufXx9_w_EUAL1troFzq3f_63k8o67hyphenhyphenRxawmT24Q4WK7Zd68TyWtn0CKg_6N50sSyVQLk9AOyOvwt94EJ3i-S6blj2e4FBDr48k9ry-yM2-x/s1600-h/differenes%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;differenes&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;differenes&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlO5XNkih_w6HjKQEfmvqXHN63PBFCmqZ1o6JjPg5AGFdvgVxLIwOHOgFkFTWxfv1y2mJhCn5z4-LWhQ49db1UHysq63AyrrERpTriGLlupXpIFhyphenhyphenbfK4lFrWfO5ky9oMVlP9sxfKpG9zU/?imgmax=800&quot; width=&quot;578&quot; height=&quot;336&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Getting the pictures from a local folder.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXYmxmMVfo9f26eze6XrNwDPF-aWYebiylOT4DBi9RkLSALnL4gwIRx1tnB9Xspp9VCopWHNSJswnbo9yTxezpQpyP_w9TRGc4D_NCx7ZBw7sMG4o-EniWgKWQ0FChBEVBo4r6gw2J1agO/s1600-h/folders%25255B3%25255D.png&quot;&gt;&lt;img title=&quot;folders&quot; style=&quot;border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px&quot; border=&quot;0&quot; alt=&quot;folders&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBlLSDVLSKM1iAiRL6kzrgs5Jmy3inIJ6CQ2OK4ZiEUt-HhHx7OV-96F7lfqgBuNoykyWFCvMmIgfgGImFtfkpyuC0b5B6elgnw38hqQhWGjjnhfhHmrTKrNMArATdcOkMzpBR8QTorisK/?imgmax=800&quot; width=&quot;569&quot; height=&quot;298&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;There is no database access.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/4325619630158222964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/4325619630158222964' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/4325619630158222964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/4325619630158222964'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/10/bcl-team-blog-provides-more-information.html' title='BCL Team Blog provides more information on code reuse (Portable Libraries part 4)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwSq6qovpurNZ80Lf2y34p8scwyHrucPvJt-1rvX06NglRwt8mOAHq-aGMgZfHJUASVcFDRaGfJS5c6a9sVnAtjA-BB4B_Td7oriD2QBF-jrDZUHv6c_sAWo7Ig3QD-A7-rAqpG5dZ_mRA/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-7483327055444716686</id><published>2011-09-28T11:40:00.001+02:00</published><updated>2011-09-28T12:21:17.570+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="portable libraries"/><title type='text'>.NET portability is not an afterthought (adding another layer of indirection - Portable Libraries part 3)</title><content type='html'>&lt;p&gt;Before &lt;a href=&quot;http://www.buildwindows.com/&quot; target=&quot;_blank&quot;&gt;//build/&lt;/a&gt; I was not aware of the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/gg597391.aspx&quot; target=&quot;_blank&quot;&gt;Portable Class Libraries Project&lt;/a&gt;. The origin of the project is the notion that the number of platform that provide .NET support has increased from one to four and that this number will increase in the future. Making .NET available on more platforms is the future of .NET.&lt;/p&gt; &lt;p&gt;The &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/gg597391.aspx&quot; target=&quot;_blank&quot;&gt;Portable Class Libraries Project&lt;/a&gt; was the first attempt of solving the portability issue but it ran into some constraints. One of them was the increasing complexity: “Portability is an afterthought”.&lt;/p&gt; &lt;p&gt;After watching some of the presentation at &lt;a href=&quot;http://www.buildwindows.com/&quot; target=&quot;_blank&quot;&gt;//build/&lt;/a&gt; and experimenting with Visual Studio Express for Windows Developer Preview I thought that the whole purpose of creating a portable library was to bridge the gap between .NET and the WinRT.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8hM_hFV3AgoDkP7F0kqJK8tiE6rfOE1Eot-fYTBp5TIW_qmhhpAsofcPlo6x08LEnpnLEt2tSw5FpeYBfGaNC306EiPTCO3INYzyB52ov6lCyztyp2UpPmTgYMvZntuEAoVgn7_c3hCxa/s1600-h/ClassLibrary3.png&quot;&gt;&lt;img title=&quot;ClassLibrary&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;ClassLibrary&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgap3Z7uL5YJ5gVLLRchzRnhtQ6MCYyrF7pktu0IC6zbx5GLD4hnGn-7q5wp7C8SMc0oFKPNEocmLydtYwT63Qct3Xfbb7tp9yTvlxpBIE5U5kjPoIFlcI9KZAlOJFYU0BQB1r1PIZyQY4n/?imgmax=800&quot; width=&quot;651&quot; height=&quot;228&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is not the case. Yesterday I watched &lt;a href=&quot;http://channel9.msdn.com/Shows/Going+Deep/NET-45-David-Kean-and-Marcea-Trofin-Portable-Libraries&quot; target=&quot;_blank&quot;&gt;.NET 4.5: Portable Libraries&lt;/a&gt; by David Kean and Mircea Trofin at Channel 9. It all made more sense to me.&lt;/p&gt; &lt;p&gt;&lt;iframe style=&quot;height: 288px; width: 512px&quot; src=&quot;http://channel9.msdn.com/Shows/Going+Deep/NET-45-David-Kean-and-Marcea-Trofin-Portable-Libraries/player?w=512&amp;amp;h=288&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The show:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The first 15 minutes explains portability and the first version of the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/gg597391.aspx&quot; target=&quot;_blank&quot;&gt;Portable Class Libraries Project&lt;/a&gt;.  &lt;li&gt;15:00 whiteboard time.  &lt;li&gt;Explaining the first way to solve portability problem:  &lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL2OYpsClQoo9EhCSdWLv7OmkQlUFfAQxDe9FUXIXaWnEHW3spVHCamJwTmkut2pcsCR3ZUiSohDoFM2t1pL5Znifl7iNutksmp9tqc4FzwFVi2_e0IjrbkEmt89WHT6xj-fiLxmdDoSlj/s1600-h/wb13.png&quot;&gt;&lt;img title=&quot;wb1&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb1&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGFX9jaBi9NYysppPibPqab-bUqwB2wCugYK162KHpWHfS1KH0VQtEQ0ywI9Oz1GvOO08kLDva-0bBHkTxgqexjw_OZda5LFJrHAK0Frq9hde3J00uYwV2sIRmBDJDG1-mS4Zaw5jJ8Oxo/?imgmax=800&quot; width=&quot;360&quot; height=&quot;213&quot;&gt;&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY1XKHbOaWiDvy56upHGMChS1Pqd5KQRX5Krzxx79ZhxPOFY8FpgA1wTWBB6aok75z9UTuZqK3mgVS4glbZ9vMXUF8GwzoqsCh05ueYmUPhSgaiKNBRzRWHnBKHyjyVkL3EzfLHn__8sm5/s1600-h/wb26.png&quot;&gt;&lt;img title=&quot;wb2&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb2&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXTY9gp8nse2eIVRvIjQUC19EG-cg58uQpT219uGpC91b1UDu6zVGakWn1W5l671cDDSNTd1mhhccyk72f9rpNzhhZGHLRnDoSe1_Pqb0RJfFfVcW5lSYOA7bl8cq-pAx4k0Cl15GEm4Lk/?imgmax=800&quot; width=&quot;415&quot; height=&quot;126&quot;&gt;&lt;/a&gt;  &lt;li&gt;Explaining the problems with System.NET  &lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvZRlTelkiWobHxktuZi0jjmz4OFKkXIhQs0stGM6psTFqDfQivbaPuUMmzpugoxqi5Ceh6myS2BrrMFr7yITLeMZEHpDrm29dZcIdUIRiDiLPrmK38FmllqM_ozOYF6B9XB9o7ZM9jGC2/s1600-h/wb36.png&quot;&gt;&lt;img title=&quot;wb3&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb3&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfNHPwCj5MIgQdbQJrUUqfiv1Yv9JD4ZQoWKCqkZM_-Qnk1QJW_f2uhImDlnSkq1w4MR9vDGmt2jvGnDQTtYIN5-AG6akA_OEJtCswZ8_3TVvv-rHJR4GnzpJBacnf9GlVP3XPmcZMmFcZ/?imgmax=800&quot; width=&quot;391&quot; height=&quot;265&quot;&gt;&lt;/a&gt;  &lt;li&gt;22:00 the new solution: one portable library by design.  &lt;li&gt;Portability is not an afterthought  &lt;li&gt;28:00  &lt;ul&gt; &lt;li&gt;You program against a contract  &lt;li&gt;It is up to the platform to implement the contract  &lt;li&gt;Type forwarding:&lt;br&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1s7layggbj2Rjwkba_odnzjqeqO1bYt6j7Atw1Z6TOLRP45s7x45Iw81WdetYLMrdDtg-gzxGS8CgTpipR-w9_KCZFoQO5Z7KyUcPYDh76SZiI4cFI2SsaIKci44cTpOJdruE0Yt7yPSK/s1600-h/wb53.png&quot;&gt;&lt;img title=&quot;wb5&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb5&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicZydl6tfZqIRwZM7M6KXzENcXsojPce8dGPK6dQG-k5X9sEaMOWmP01eVbVkZoeC1nUE-ms7_nm3p8cRaMSaoM2ELRPwD7hhCqyilsYQ_dibjc61BsG_0OUtDkQDx9QUOs5aqAHK4oEut/?imgmax=800&quot; width=&quot;355&quot; height=&quot;124&quot;&gt;&lt;/a&gt;  &lt;li&gt;You program against the exposed api.  &lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh70jdjk6sVhYUGZJOHwzyxfs2H-UBwrNOlFohv0ER51nqP69hERV38jLsGZDCM07rFDGcsByaygLW0jUwNBXLqhElNEAwKk6tEsT54gMrSwYGO_eCahgpFfQNlFp29pcaBps42CKU-1SYB/s1600-h/wb43.png&quot;&gt;&lt;img title=&quot;wb4&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb4&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR-8bxo-poxn24yHh2eH5QOp1xPHeCjUzf6NeJaswrlrjJWPfR4nE7YWrE82LfyRX31MX0gSPpt4br0z0ZMvhJvJKIN-V-AyBFW1O-nxlWptr7oJdDUyG2LHto2Dep-1QonZVBTkG5Z19o/?imgmax=800&quot; width=&quot;291&quot; height=&quot;283&quot;&gt;&lt;/a&gt;  &lt;li&gt;And the GAC will forward to dll that implements the actual code.  &lt;li&gt;33:00 Portability is a first class citizen&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;35:00 It is about granularity a method is too small a dll is too big.  &lt;li&gt;36:00  &lt;ul&gt; &lt;li&gt;Q: Are there two gacs in the Windows 8 world?  &lt;li&gt;A: there is one gac. The metro mode is under “us”.&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;37:00 breaking changes:  &lt;ul&gt; &lt;li&gt;Type  &lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsIabN0Gejg9IL7tYpUH0pbm6phurNBcvhwB1GbQ2zejyzKh1iY87yZGLfFu4riWH1tmsQX6d_R6GMvMAVLJxsrxm31Fh3WcmmsJ7GXexNsaBuSBFgixK7brIGHIdR6aYE8ORPJp_-7WcK/s1600-h/wb63.png&quot;&gt;&lt;img title=&quot;wb6&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb6&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp-lSWOldCt87AR_uKkE_lHDLvqkasukGsxh_qX65hMI5KFFWmNHlMVQ6vSA2ZaGdV31UaPWJz3nNO8KNvf3IKJd5sxQQYvivigRjddY06tIygZxlEehUUGpu3hnz2vGJW6MbWBrM0vnWM/?imgmax=800&quot; width=&quot;391&quot; height=&quot;225&quot;&gt;&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8n2ziFBg_8XFZUssjiqngJQovrN9rKGYZNsvjsz4TL-ezcpafqvYALFkM9WgwzFGpr0QRq5BCl1OHsDimmAUBlTFRvMxx-G7BHpMZf3ulF2QhQEOGEp2gwZn9VbYDNbLu42YSCkgS76uR/s1600-h/wb73.png&quot;&gt;&lt;img title=&quot;wb7&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;wb7&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6mvUqb4u8xFMKh8IKkI2PyxgfXNQwhJNysX-XiKKo1rkpc1-D79rhvMxO2EMNCnJWEyzkbvqQ25eijXWnvJX6WHluB-rdLNV5uungNUuzXkYMMVOq24XsFd32GH7HczYLW4rQ7Nlw9GtY/?imgmax=800&quot; width=&quot;394&quot; height=&quot;284&quot;&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;45:00 Close and Dispose. Close is disposed, no more closing just disposing.  &lt;li&gt;They reference: &lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-930C&quot;&gt;A .NET developer&#39;s view of Windows 8 app development&lt;/a&gt; by Krzysztof Cwalina  &lt;li&gt;50:00 .NET has a great future with portability in mind.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;So it makes sense to fix and recompile your legacy libraries. You can port them to all platforms that will have .NET available.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/7483327055444716686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/7483327055444716686' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7483327055444716686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/7483327055444716686'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/09/net-portability-is-not-afterthought.html' title='.NET portability is not an afterthought (adding another layer of indirection - Portable Libraries part 3)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgap3Z7uL5YJ5gVLLRchzRnhtQ6MCYyrF7pktu0IC6zbx5GLD4hnGn-7q5wp7C8SMc0oFKPNEocmLydtYwT63Qct3Xfbb7tp9yTvlxpBIE5U5kjPoIFlcI9KZAlOJFYU0BQB1r1PIZyQY4n/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-6008357746391457289</id><published>2011-09-22T11:22:00.002+02:00</published><updated>2011-09-28T09:00:58.753+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="Legacy"/><category scheme="http://www.blogger.com/atom/ns#" term="Metro"/><category scheme="http://www.blogger.com/atom/ns#" term="WinRT"/><title type='text'>Reuse of legacy software by WinRT and Metro (Windows 8) (Portable Libraries part 2)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;This is a follow up to my previous post &lt;a href=&quot;http://ps-a.blogspot.com/2011/09/create-metro-app-in-f-not.html&quot; target=&quot;_blank&quot;&gt;Create a Metro App in F# (NOT)&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Things become quit complex if you want to reuse your windows legacy software. In this case legacy has a positive connotation. Legacy software is an asset of you and/or your company.&lt;/p&gt; &lt;p&gt;Suppose one want to reuse it and make it available for a Metro app on Windows 8 what are your options? After watching some of the build presentations:  &lt;ul&gt; &lt;li&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-875T&quot; target=&quot;_blank&quot;&gt;Windows Runtime internals: understanding &quot;Hello World&quot;&lt;/a&gt; by Matt Merry  &lt;li&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-877T&quot; target=&quot;_blank&quot;&gt;Being pragmatic by leveraging existing code in Metro style apps&lt;/a&gt; by Jason Olson  &lt;li&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-930C&quot; target=&quot;_blank&quot;&gt;A .NET developer&#39;s view of Windows 8 app development&lt;/a&gt; by Krzysztof Cwalina  &lt;li&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-876T&quot; target=&quot;_blank&quot;&gt;Ten Tips When Writing a Hybrid Language Metro style Application&lt;/a&gt; by Brent Rector  &lt;li&gt;&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-531T&quot; target=&quot;_blank&quot;&gt;Using the Windows Runtime from C# and Visual Basic&lt;/a&gt; by Harry Pierson and Jesse Kaplan&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I came up with the following flow chart:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcnAjUJ1spmgUnqVaFneQpj2oH0_EYPX1l7Auvb10dh1S8jm5dgaycUhfahN4WgCAFfR5lJrzcYbxZpdQzLpBrTRlomdu8NsxEmxLwlBPfCUCYyPvJjXp1Chgw_LcPm7Xz_FTE_35eiLXc/s1600-h/LegacyWinRT_4%25255B4%25255D.png&quot;&gt;&lt;img title=&quot;LegacyWinRT_4&quot; style=&quot;border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px&quot; border=&quot;0&quot; alt=&quot;LegacyWinRT_4&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYMmklFPyi_FjwVaDVQnvYu0HT3dtJfyMVg_BSGAnei_kyIMaD0cSx18febopIHqwjAAGTgtpzE3GeJZdvppPypWLg5PbIBrOIxiQq95RC5mUYmESuCWuNf5rQLR4EyrqEAVZOBh3sQO8u/?imgmax=800&quot; width=&quot;623&quot; height=&quot;652&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;You can reuse html, css and JavaScript.  &lt;li&gt;I am not an expert on C++, COM, etc. so I do not know.  &lt;li&gt;If you have only a dll you cannot use it.  &lt;li&gt;If you have source code that references a language dll (like F#) or have no options today. This will change when the final product becomes available.  &lt;li&gt;If you want to create a Metro Style project in C++ or JavaScript you can reuse your components code by fixing issues and recompile it to a WinMD file (WinRT component). Some issues can be exposing:  &lt;ul&gt; &lt;li&gt;non WinRT types  &lt;li&gt;non sealed classes  &lt;li&gt;non system provided generic types&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;If you want to create a Metro Style project and this is one of the .NET languages you can reuse your components code by fixing issues and recompile it to a dll. Some issues can be:  &lt;ul&gt; &lt;li&gt;Streams&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: This is my current understanding, based on the presentations I viewed. If you have other information available please leave a note in the comments.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/6008357746391457289/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/6008357746391457289' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6008357746391457289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6008357746391457289'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/09/reuse-of-legacy-by-winrt-and-metro.html' title='Reuse of legacy software by WinRT and Metro (Windows 8) (Portable Libraries part 2)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYMmklFPyi_FjwVaDVQnvYu0HT3dtJfyMVg_BSGAnei_kyIMaD0cSx18febopIHqwjAAGTgtpzE3GeJZdvppPypWLg5PbIBrOIxiQq95RC5mUYmESuCWuNf5rQLR4EyrqEAVZOBh3sQO8u/s72-c?imgmax=800" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-296687516561839247</id><published>2011-09-21T01:54:00.001+02:00</published><updated>2013-01-31T11:11:21.108+01:00</updated><title type='text'>Create a Metro App in F# (NOT) (Portable Libraries part 1)</title><content type='html'>&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;strong&gt;update January 24, 2013&lt;/strong&gt;: you are now able to create “Metro apps”: &lt;/span&gt;&lt;a href=&quot;http://ps-a.blogspot.nl/2013/01/windows-store-apps-with-f-part-1-make.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Windows Store Apps with F# (part 1) : Make things as simple as possible, but not simpler.&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Today you can follow the all-F# approach (&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/hh394149.aspx&quot; target=&quot;_blank&quot;&gt;Build MVVM Applications in F#&lt;/a&gt;). This is not the easiest way to build a solution, it is not the preferred way, but it is an option. &lt;br /&gt;
Don Syme presented last Friday in his &lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-904T&quot; target=&quot;_blank&quot;&gt;build talk&lt;/a&gt; the following slide.&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcGg_NxmuiAkNUL16ca5k11oP2dCaER6XVYVVN5pES0EZe9GTPbNlm-ymTdmUZbMHegY1cJewNXUzKcE1B3951xRG9O64HSpeg90b1bGUIWjkoRVbLjF9Aigd2MN9NLKsGL3qu-RSDVIs5/s1600-h/FSharpMetro%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;FSharpMetro&quot; border=&quot;0&quot; height=&quot;277&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqHuhnGQzjuMgbEGUJl8PUy0Iti_VLAKoPGYjwZVvBeRmBinlmlNuM6foE3v3JUzTQ0rGZzajr499iYvoYvCs_CrFAVa5tAfn8aQPLIJA3Jk0JFlQAY9uZ4rvwPZ2rO5MvA5WtmqGf5T7V/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;FSharpMetro&quot; width=&quot;490&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
When he explained this it was not completely clear to me what this meant.&lt;br /&gt;
Does this tell us that we cannot create a F# Metro front-end today but we will when F# 3.0 is ready? Or does this mean that you cannot create a F# 3.0 project and reference it from a C# or a VB Metro front-end app in one solution?&lt;br /&gt;
Today I watched some other presentations of day 4 of build:&lt;br /&gt;
&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-875T&quot; target=&quot;_blank&quot;&gt;Windows Runtime internals: understanding &quot;Hello World&quot;&lt;/a&gt; by Matt Merry&lt;br /&gt;
&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-877T&quot; target=&quot;_blank&quot;&gt;Being pragmatic by leveraging existing code in Metro style apps&lt;/a&gt; by Jason Olson&lt;br /&gt;
&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-930C&quot; target=&quot;_blank&quot;&gt;A .NET developer&#39;s view of Windows 8 app development&lt;/a&gt; by Krzysztof Cwalina&lt;br /&gt;
&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-876T&quot; target=&quot;_blank&quot;&gt;Ten Tips When Writing a Hybrid Language Metro style Application&lt;/a&gt; by Brent Rector&lt;br /&gt;
&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-531T&quot; target=&quot;_blank&quot;&gt;Using the Windows Runtime from C# and Visual Basic&lt;/a&gt; by&amp;nbsp; Harry Pierson and Jesse Kaplan&lt;br /&gt;
and experimented with Visual Studio 11 (Developer Preview and Express for Windows Developer Preview).&lt;br /&gt;
It became clear to me that you cannot create a Metro style solution that references a project that references .NET dll&#39;s that are not part of the .NET Profile for Metro style apps.&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOU_TqGeHgy7Ysex_laIL1F_rO7Q4-IKw7kmjJV3WBYgNxA5EkwSuxm3Qm-esjY1UpRiD3HzzHUWIoLcco9rQCeOBIWu3DbxB9qvbQNbCsCzshYWczH62F2jGKZnhjGV9W5a69Zc0CayLm/s1600-h/requirements%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;requirements&quot; border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9mgPDPUsupnHhELLCnMAAUMnmw5A74Jk0j-XoCg6ZN8ROEI4gGDh5CSVB_jfIzUqCNRi7o5_TDc3fdAnOE7uIrVVsblBG1R7JsHbSxYpmW-DzTn5x8kdGb5PZNVGaCivY3bmvBnsitWM_/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;requirements&quot; width=&quot;507&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7lxc9_UH6V8KnG8Z7UMRbw_e-NY2rHycfSmggn8t82Su__UvuVdYKcUTE7qHSsFTy9wa7KNbSgMAxaDWY30sDwVePFB81-JHK8BNs9Pd8-b7Qi223Qd34ZKQaPU4Ub58grifEtEQ8OU6G/s1600-h/profile%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;profile&quot; border=&quot;0&quot; height=&quot;294&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIpxuGphismTVaAIwhE9TrjRKLI4aMcS_vaInWuh3sVpL1Wh6VIEG-HG2loX3SLzIFibw4B9VqxC9ICsnsH_pZ8oHTGs3EX0TRiK7ji1JeGpf6NTMIiIrD61qED8Yl8ykLgpajX5BpTtjV/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;profile&quot; width=&quot;505&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
The F# dll is one of them today. So creating a Metro app in C#/VB/C++/JavaScript that references a F# project is not possible.&lt;br /&gt;
This should be possible when F# 3.0 becomes available. Will it be possible to create an all-F# Metro app in the F# 3.0 time frame? For me, this is still an unanswered question.&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3Qr0ItINp4nhXxo02XDlBDoCWV48ybU66NpivqMy3wMXOpIYMZW1UVJK9RJrwy1LFX1yAxPgFlS7GIcioXfsPdhpju37J0NkQ-gWlduyFXIXwOT9UKQoRve5OsIYhPA8xfZo_K-GMLMQY/s1600-h/WinRt%25255B3%25255D.png&quot;&gt;&lt;img alt=&quot;WinRt&quot; border=&quot;0&quot; height=&quot;261&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7MkZ-CfT7XTfu_iyN3bSilW7K0SgBk7FLqdDdWz7HAmZcaWmp1ndMyeV2hUjurtBDBWw1bQwFqM5LMv80j-Tz0CmDpaPH64Oy5FBd7Zf3XCMDxEpGwx2GVOO_NSvtRfYl1qp9kk9VALTm/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;WinRt&quot; width=&quot;455&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Another consequence of this approach: when you intend to reuse your .NET dll&#39;s you have to recompile your code as WinMD files. So you need to own the source code.  &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhRGndsJIFMAtw3DunXfYxFV874Nzq9U-qbEbCH5OT4AWXSPRaemcejH296oCsXelh48DXDX35dyvJEOVpQJILSrv9x9hNGvIYLY8LhTtXfiw6l5hPtZdSR5wjhSTYPduTZHFpKeHNW1yS/s1600-h/WinMD%25255B2%25255D.png&quot;&gt;&lt;img alt=&quot;WinMD&quot; border=&quot;0&quot; height=&quot;53&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiklaUCcBbZffMfoML5ykauqHQVjboQ5RAcgpxLDuwZ2udbEU0Ui5D86e1MEiU6cs0k1n5peva8xR0zeRRVUrYSM7px-_QW75ppQMB7UYxl9jdA_ruIl7v9QJrZKGBP5pu7s_6GAGZFKu-z/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;WinMD&quot; width=&quot;244&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
This are the restrictions:&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW7YrAYaMD-i2rOZBYZocNY1Z-2Xp2-zJ-va3qzglK_1nZjgSayHeXc7FyO-4ayUuTitthphp8VE63Ss0_iKWi9hxKioa08wp3eHNb6dOyEZbIK_2CxCuPRzxRGFyrb5hWH_zXlPMy3o00/s1600-h/Restrictions%25255B7%25255D.png&quot;&gt;&lt;img alt=&quot;Restrictions&quot; border=&quot;0&quot; height=&quot;264&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUnIWEsLuHeIKEJSKDVn0LDkcXDAgAC9Gx974o9hLnqzJemd9TsjdUw1EQJlEJFtlIdYQoSBVWM_D5nswwBkIgBAhll1suaydOMWZLHZfIP1FpTCAIzmsvriJXlJaUQh5O7t_pK-vANvjO/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;Restrictions&quot; width=&quot;459&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;strong&gt;Update&lt;/strong&gt;(September 21, 2011):&lt;br /&gt;
&lt;a href=&quot;http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-877T&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Jason_Olson&quot; border=&quot;0&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSoQ92SosmCY7rAdciZeErIRfBkqluPB1BsYF3ovlVOAGK5eIgKgEv3Y90OJGgFXFlTmpmxYMQL_tivCyUhCrhGG7AG48g80rD-L0K6VDrXwSNVs969cija7pQa8tWGTUTWTSbIUF1xscX/?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;Jason_Olson&quot; width=&quot;487&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/296687516561839247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/296687516561839247' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/296687516561839247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/296687516561839247'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/09/create-metro-app-in-f-not.html' title='Create a Metro App in F# (NOT) (Portable Libraries part 1)'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqHuhnGQzjuMgbEGUJl8PUy0Iti_VLAKoPGYjwZVvBeRmBinlmlNuM6foE3v3JUzTQ0rGZzajr499iYvoYvCs_CrFAVa5tAfn8aQPLIJA3Jk0JFlQAY9uZ4rvwPZ2rO5MvA5WtmqGf5T7V/s72-c?imgmax=800" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-914601964371312602</id><published>2011-09-15T10:39:00.001+02:00</published><updated>2011-09-30T14:17:14.483+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dotnetmag"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="NuGet"/><category scheme="http://www.blogger.com/atom/ns#" term="oData"/><title type='text'>F# type providers: oData from NuGet</title><content type='html'>&lt;p&gt;Yesterday &lt;a href=&quot;http://blogs.msdn.com/b/fsharpteam/archive/2011/09/14/f-3-0-developer-preview-now-available.aspx&quot; target=&quot;_blank&quot;&gt;F# 3.0 Developer Preview&lt;/a&gt;&amp;nbsp; became available at the MSDN Site. It will be general available on Friday.&lt;/p&gt; &lt;p&gt;One of the new features is the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/hh156509(v=VS.110).aspx&quot; target=&quot;_blank&quot;&gt;type provider&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;This little snippet shows how easy it is to query a site that provides oData. NuGet is an example of a site that provides &lt;a href=&quot;http://haacked.com/archive/2011/02/23/how-to-find-out-which-nuget-packages-depend-on-yours.aspx&quot; target=&quot;_blank&quot;&gt;oData&lt;/a&gt;.&lt;/p&gt; &lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2582b3c4-f242-468e-b2db-7d7a0da84800&quot; class=&quot;wlWriterSmartContent&quot;&gt; &lt;div style=&quot;border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid&quot;&gt; &lt;div style=&quot;padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px&quot;&gt;Code Snippet&lt;/div&gt; &lt;div style=&quot;background: #ddd; overflow: auto&quot;&gt; &lt;ol style=&quot;padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px&quot;&gt; &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;#r&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;FSharp.Data.TypeProviders.dll&quot;&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;#r&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;System.Data.Services.Client.dll&quot;&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;open&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; Microsoft.FSharp.Data.TypeProviders&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;[&amp;lt;Generate&amp;gt;]&lt;/span&gt;  &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; NuGet = ODataService&amp;lt;&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;http://packages.nuget.org/v1/FeedService.svc/&quot;&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&amp;nbsp; &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; dbNuGet = NuGet.GetDataContext()&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; packages = dbNuGet.Packages&lt;/span&gt;  &lt;li&gt;&amp;nbsp; &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; nuGetQuery = &lt;/span&gt; &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; query { &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; package &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; packages &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;do&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where (package.Tags.Contains(&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;fsharp&quot;&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;) &amp;amp;&amp;amp; package.IsLatestVersion)&lt;/span&gt;  &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select package }&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&amp;nbsp; &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #0000ff&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; printPackage (package:NuGet.ServiceTypes.PublishedPackage) =&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printfn &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;- - - - - - - - - - - - - - - - - - - -&quot;&lt;/span&gt;  &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printfn &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;Title: %s&quot;&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; package.Title&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printfn &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;Authors: %s&quot;&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; package.Authors&lt;/span&gt;  &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printfn &lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #800000&quot;&gt;&quot;Description: %s&quot;&lt;/span&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt; package.Description&lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&amp;nbsp; &lt;li&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;  &lt;li style=&quot;background: #f3f3f3&quot;&gt;&lt;span style=&quot;background: #ffffff; color: #000000&quot;&gt;nuGetQuery |&amp;gt; Seq.iter printPackage&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;This is the result:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjpiunY-0p_YA1fWVStiHptSNw89m0D3CNOQJ5tAu6dUjwa8hUdpywqQipyR_nzw49J3AleQmsl56AEXoIObsfBFucU-sqjg8SVBnzRyDvCLa1Rdcu_qh8xonbjHif63tBkkLkA6dESqpW/s1600-h/result%25255B7%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;result&quot; border=&quot;0&quot; alt=&quot;result&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjywozTL_PspKdpyvuIdHEfb_cnIauzCrpmsVkP38jKnwlG1nz8fIbV_HblQx4ciAz-p3EiBt1JSbawQcNuEfYhcGjG4ukk0eTx4q_MaPf3IZZL9JwT1pqPi6Ep_kOjia8ELTAVFr4JNK84/?imgmax=800&quot; width=&quot;563&quot; height=&quot;395&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;One of the nice features of type providers is intellisense for the available types.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3S9AKTGHo4A-QvR1f7oY8TnOg-jnaQq38b1CjHoChS9E4M1btI-V3EWtsmLhHFodNHUn3Hosc6IEJcWyOl8o675EtjzSdVzRl5A4l51MkZ-lCYQxnGLO6ELE_1Vhsh-9xToJaS_0y24Y_/s1600-h/intellisense%25255B4%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;intellisense&quot; border=&quot;0&quot; alt=&quot;intellisense&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht1Dds7yC29RlJGgaUX6WB1-fwe7GqHWXd2arHt7DSSuTN-yKcaoe_q3rT2M51yrdQGm_zN-zvUSFXy4MMESfS8YDNy3rTPETJOFlHAzWCDFhkNzeHh9hp1xN-7bOoIk_bt4HzRKm61h4e/?imgmax=800&quot; width=&quot;329&quot; height=&quot;218&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It is possible to create your own type provider.&lt;/p&gt; &lt;p&gt;More information will be available on Friday. Don Syme will present all the details at build: &lt;a title=&quot;http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-904T&quot; href=&quot;http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-904T&quot;&gt;http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-904T&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;update: &lt;a href=&quot;http://blogs.msdn.com/b/fsharpteam/archive/2011/09/24/developing-f-type-providers-with-the-f-3-0-developer-preview-an-introductory-guide-and-samples.aspx&quot; target=&quot;_blank&quot;&gt;Writing F# Type Providers with the F# 3.0 Developer Preview - An Introductory Guide and Samples&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/914601964371312602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/914601964371312602' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/914601964371312602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/914601964371312602'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/09/f-type-providers-odata-from-nuget.html' title='F# type providers: oData from NuGet'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjywozTL_PspKdpyvuIdHEfb_cnIauzCrpmsVkP38jKnwlG1nz8fIbV_HblQx4ciAz-p3EiBt1JSbawQcNuEfYhcGjG4ukk0eTx4q_MaPf3IZZL9JwT1pqPi6Ep_kOjia8ELTAVFr4JNK84/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-8443279574091335394</id><published>2011-09-01T14:27:00.001+02:00</published><updated>2011-09-08T09:33:55.070+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><category scheme="http://www.blogger.com/atom/ns#" term="Monad"/><title type='text'>Monads for .NET developers</title><content type='html'>&lt;p&gt;I have written an article for the Dutch developer magazine of &lt;a href=&quot;http://www.sdn.nl/&quot;&gt;SDN&lt;/a&gt; (Magazine 111). It is titled: “Monads voor de .NET-ontwikkelaar”.&lt;/p&gt; &lt;p&gt;In this post I will list some of the available resources on monads for .NET developers:&lt;/p&gt; &lt;h3&gt;C# resources&lt;/h3&gt; &lt;h4&gt;Books:&lt;/h4&gt; &lt;ul&gt; &lt;li&gt;Tomas Petricek &amp;amp; Jon Skeet: &lt;a href=&quot;http://www.amazon.com/Real-World-Functional-Programming-Examples/dp/1933988924/ref=sr_1_2?ie=UTF8&amp;amp;qid=1312719498&amp;amp;sr=8-2&quot; target=&quot;_blank&quot;&gt;Real World Functional Programming: With Examples in F# and C#&lt;/a&gt;, &lt;a href=&quot;http://manning.com/petricek/&quot; target=&quot;_blank&quot;&gt;website&lt;/a&gt;  &lt;li&gt;Oliver Sturm: &lt;a href=&quot;http://www.amazon.com/Functional-Programming-Techniques-Projects-Programmer/dp/0470744588/ref=sr_1_1?ie=UTF8&amp;amp;qid=1312719498&amp;amp;sr=8-1&quot; target=&quot;_blank&quot;&gt;Functional Programming in C#: Classic Programming Techniques for Modern Projects&lt;/a&gt;, &lt;a href=&quot;http://www.wrox.com/WileyCDA/WroxTitle/Functional-Programming-in-C-Classic-Programming-Techniques-for-Modern-Projects.productCd-0470744588.html&quot; target=&quot;_blank&quot;&gt;website&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;Web:&lt;/h4&gt; &lt;ul&gt; &lt;li&gt;Wes Dyer: &lt;a href=&quot;http://blogs.msdn.com/b/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx&quot; target=&quot;_blank&quot;&gt;The marvels of monads&lt;/a&gt;  &lt;li&gt;Mike Hadlow: &lt;a href=&quot;http://mikehadlow.blogspot.com/2011/01/monads-in-c1-introduction.html&quot; target=&quot;_blank&quot;&gt;Monads in C#–1. Introduction&lt;/a&gt;&lt;/a&gt;.  &lt;li&gt;Derick Bailey: &lt;a href=&quot;http://lostechies.com/derickbailey/2010/09/30/monads-in-c-which-part-is-the-monad/&quot; target=&quot;_blank&quot;&gt;Monads in C#: Which Part Is The Monad?&lt;/a&gt;  &lt;li&gt;Matthew Podwysocki: &lt;a href=&quot;http://weblogs.asp.net/podwysocki/archive/2008/10/13/functional-net-linq-or-language-integrated-monads.aspx&quot; target=&quot;_blank&quot;&gt;Functional .NET - LINQ or Language Integrated Monads?&lt;/a&gt;  &lt;li&gt;Tomas Petricek: &lt;a title=&quot;http://tomasp.net/blog/idioms-in-linq.aspx&quot; href=&quot;http://tomasp.net/blog/idioms-in-linq.aspx&quot; target=&quot;_blank&quot;&gt;Beyond the Monad fashion (I.): Writing idioms in LINQ&lt;/a&gt;  &lt;li&gt;Mauricio Scheffer: &lt;a href=&quot;http://bugsquash.blogspot.com/2011/04/refactoring-to-monadic-c.html&quot; target=&quot;_blank&quot;&gt;Refactoring to monadic C#&lt;/a&gt;  &lt;li&gt;Erik Meijer: &lt;a href=&quot;http://delivery.acm.org/10.1145/2030000/2024658/p60-meijer.pdf?ip=83.81.189.54&amp;amp;CFID=38317202&amp;amp;CFTOKEN=68910799&amp;amp;__acm__=1315219994_afb647f60a29db0cea015252ee91ed4b&quot; target=&quot;_blank&quot;&gt;The World According to LINQ&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;F# resources&lt;/h3&gt; &lt;p&gt;Computation Expressions are addressed in most of the available F# books (&lt;a href=&quot;http://www.amazon.co.uk/Professional-2-0-Wrox-Programmer/dp/047052801X/ref=cm_lmf_tit_10&quot; target=&quot;_blank&quot;&gt;Professional F# 2.0&lt;/a&gt; does not): &lt;a href=&quot;http://www.amazon.co.uk/F-and-functional-programming/lm/R14JYBWI11LWQS&quot; target=&quot;_blank&quot;&gt;F# and functional programming&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;Web:&lt;/h4&gt; &lt;ul&gt; &lt;li&gt;Wiki: &lt;a href=&quot;http://en.wikibooks.org/wiki/F_Sharp_Programming/Computation_Expressions&quot; target=&quot;_blank&quot;&gt;Computation Expressions&lt;/a&gt;  &lt;li&gt;Don Syme: &lt;a href=&quot;http://blogs.msdn.com/b/dsyme/archive/2007/09/22/some-details-on-f-computation-expressions-aka-monadic-or-workflow-syntax.aspx&quot; target=&quot;_blank&quot;&gt;Some Details on F# Computation Expressions&lt;/a&gt;  &lt;li&gt;Francois Vanderseypen&lt;strong&gt; :&lt;/strong&gt; &lt;a title=&quot;http://visualizationtools.net/default/categories-for-dummies/&quot; href=&quot;http://visualizationtools.net/default/categories-for-dummies/&quot; target=&quot;_blank&quot;&gt;Categories, monads and F# for dummies&lt;/a&gt;  &lt;li&gt;Steffen Forkmann: &lt;a href=&quot;http://www.navision-blog.de/2009/10/23/using-monads-in-fsharp-part-i-the-state-monad/&quot; target=&quot;_blank&quot;&gt;Using monads in F# – Part I: The State Monad&lt;/a&gt;  &lt;li&gt;Brian McNamara : &lt;a href=&quot;http://lorgonblog.wordpress.com/2008/06/07/catamorphisms-part-seven/&quot; target=&quot;_blank&quot;&gt;catamorphisms part seven&lt;/a&gt;  &lt;li&gt;Ivan Towlson : &lt;a href=&quot;http://hestia.typepad.com/flatlander/2010/12/f-computation-expressions-for-beginners-part-1-whats-the-problem.html&quot; target=&quot;_blank&quot;&gt;F# computation expressions for beginners, part 1: what’s the problem?&lt;/a&gt;  &lt;li&gt;Chance Coble: &lt;a href=&quot;http://leibnizdream.wordpress.com/2008/10/21/why-use-computation-workflows-aka-monads-in-f/&quot; target=&quot;_blank&quot;&gt;Why use Computation Workflows (aka Monads) in F#?&lt;/a&gt;  &lt;li&gt;Ryan Riley: &lt;a href=&quot;http://nuget.org/List/Packages/FSharp.Monad&quot; target=&quot;_blank&quot;&gt;A monad library for F# projects&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Presentations&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;Mike Hadlow: &lt;a title=&quot;http://vimeo.com/21705972&quot; href=&quot;http://vimeo.com/21705972&quot; target=&quot;_blank&quot;&gt;on Monads @ E-VAN 29 March 2011&lt;/a&gt;  &lt;li&gt;Robert C. Martin (Uncle Bob) at the &lt;a href=&quot;http://www.ndc2011.no/&quot; target=&quot;_blank&quot;&gt;Norwegian Developers Conference&lt;/a&gt;: “&lt;a href=&quot;http://ndc2011.macsimum.no/SAL7/Torsdag/1140-1240.wmv&quot; target=&quot;_blank&quot;&gt;WTF is a Monad&lt;/a&gt;” (&lt;a href=&quot;http://ps-a.blogspot.com/2011/06/wtf-is-monad-by-robert-c-martin-in-f.html&quot; target=&quot;_blank&quot;&gt;F# code&lt;/a&gt;)  &lt;li&gt;Erik Meijer: &lt;a href=&quot;http://www.youtube.com/watch?v=UuamC0T3hv8&amp;amp;feature=relmfu&quot; target=&quot;_blank&quot;&gt;Fundamentalist Functional Programming&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-8-of-13/&quot; target=&quot;_blank&quot;&gt;Chapter 8 - Functional Parsers&lt;/a&gt;  &lt;li&gt;Bart De Smet: &lt;a href=&quot;http://www.infoq.com/presentations/LINQ-to-Everything&quot; target=&quot;_blank&quot;&gt;LINQ, Take Two: Realizing the LINQ to Everything Dream&lt;/a&gt; &lt;li&gt;Rick Minerich: &lt;a href=&quot;http://www.slideshare.net/Rickasaurus/getting-the-mvvm-kicked-out-of-your-fn-monads&quot; target=&quot;_blank&quot;&gt;Getting the MVVM Kicked Out of Your F#’n Monads&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Some theory&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;Wiki: &lt;a href=&quot;http://en.wikipedia.org/wiki/Monad_(functional_programming)&quot; target=&quot;_blank&quot;&gt;monad&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;http://haskell.org/haskellwiki/Monad_tutorials_timeline&quot; target=&quot;_blank&quot;&gt;Monad tutorials timeline&lt;/a&gt;  &lt;li&gt;Eugenio Moggi: &lt;a href=&quot;http://www.disi.unige.it/person/MoggiE/ftp/ic91.pdf&quot; target=&quot;_blank&quot;&gt;Notions of Computation and Monads&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Real-World-Haskell-Bryan-OSullivan/dp/0596514980/ref=pd_sim_b_1&quot; target=&quot;_blank&quot;&gt;Real World Haskell&lt;/a&gt;: &lt;a href=&quot;http://book.realworldhaskell.org/read/monads.html&quot; target=&quot;_blank&quot;&gt;Chapter 14. Monads&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Learn-You-Haskell-Great-Good/dp/1593272839&quot; target=&quot;_blank&quot;&gt;Learn You a Haskell for Great Good!&lt;/a&gt;: &lt;a href=&quot;http://learnyouahaskell.com/a-fistful-of-monads&quot; target=&quot;_blank&quot;&gt;A Fistful of Monads&lt;/a&gt;  &lt;li&gt;Ertugrul Söylemez: &lt;a title=&quot;http://ertes.de/articles/monads.html&quot; href=&quot;http://ertes.de/articles/monads.html&quot;&gt;Understanding Haskell Monads&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Code:&lt;/h3&gt; &lt;p&gt;The source code of the article: &lt;a href=&quot;http://psaccelerator.nl/code/MonadsVoorDeDotNetOntwikkelaar.zip&quot;&gt;MonadsVoorDeDotNetOntwikkelaar&lt;/a&gt; and &lt;a href=&quot;http://psaccelerator.nl/code/MonadsVoorDeDotNetOntwikkelaar_english.zip&quot;&gt;MonadsVoorDeDotNetOntwikkelaar_english&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/8443279574091335394/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/8443279574091335394' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/8443279574091335394'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/8443279574091335394'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/09/monads-for-net-developers.html' title='Monads for .NET developers'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-8544726627724581180</id><published>2011-08-22T13:42:00.001+02:00</published><updated>2011-08-22T13:42:34.231+02:00</updated><title type='text'>The newbie feeling</title><content type='html'>&lt;p&gt;I read a blog post:&lt;a href=&quot;http://blog.recursivity.com/post/9204470867/the-problem-with-the-scala-community&quot; target=&quot;_blank&quot;&gt;http://blog.recursivity.com/post/9204470867/the-problem-with-the-scala-community&lt;/a&gt; that triggered me to write this post.&lt;/p&gt; &lt;p&gt;I do not know the Scala community so I can not agree or disagree with the conclusion:&lt;/p&gt; &lt;p&gt;&lt;em&gt;“I love the Scala community and the eco-system around the language, but quite frankly, to foster the continued growth of the community, we need to call out the small minority of bullies on their bullshit whenever it occurs: being able to confuse and intellectually intimidate newbies to the language and community is not proving your supposed “intellectual superiority”, it is merely a reflection of an insecure ego and social incompetence.”&lt;/em&gt;&lt;/p&gt; &lt;p&gt;I do think that as a person we can not know everything of everything and even if we could one moment in time the world will change and we have to learn the new thing.&lt;/p&gt; &lt;p&gt;So we have two option: stick with what we know or accept the newbie feeling. &lt;/p&gt; &lt;p&gt;When you are a newbie you will make mistakes. My grant parents had the following text on a tile:”The only man who never makes mistakes is the man who never does anything.” I just found out it is a quote from &lt;a href=&quot;http://www.goodreads.com/quotes/show/3068&quot;&gt;Theodore Roosevelt&lt;/a&gt; (thanks Google).&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;http://www.tegelspreukmaker.nl/index.php?tt=The%20only%20man%20who%20never%20makes%20mistakes%20is%20the%20man%20who%20never%20does%20anything&amp;amp;fs=100&amp;amp;yp=50&amp;amp;ltt=1&amp;amp;lh=120&amp;amp;tg=5&amp;amp;tk=003370&amp;amp;bf=&amp;amp;fx=0&amp;amp;fy=0&amp;amp;se=0&quot;&gt;&lt;img alt=&quot;tegelspreukmaker.nl&quot; src=&quot;http://www.tegelspreukmaker.nl/includes/timthumb.php?src=/temp/imgTqaZV08C7LxD58lGtBZv1BFLA8H4aW.jpg&amp;amp;w=200&amp;amp;h=200&amp;amp;zc=1&quot; width=&quot;381&quot; height=&quot;381&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So if we want to progress we have to accept the newbie feeling, accept the insecurity and make mistakes.&lt;/p&gt; &lt;p&gt;When we want to progress we have several options, one option is to learn it all by yourself, another is to accept the support of the community.&lt;/p&gt; &lt;p&gt;The community can support you in two ways:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;one is provide knowledge&lt;/li&gt; &lt;li&gt;the other to provide mentorship&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I think a programming language community is able to provide knowledge, that is nature of the community. To provide mentorship is something else and it is very hard to provide it on line. &lt;/p&gt; &lt;p&gt;So as a newbie look for knowledge on line and find mentorship somewhere else.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/8544726627724581180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/8544726627724581180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/8544726627724581180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/8544726627724581180'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/08/newbie-feeling.html' title='The newbie feeling'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-6844814476321567107</id><published>2011-08-07T15:20:00.001+02:00</published><updated>2011-08-09T20:48:26.244+02:00</updated><title type='text'>The difference between SelectMany and Select in LINQ</title><content type='html'>&lt;p&gt;This is follow up on my previous blog post:&lt;a title=&quot;Adding xml strings in C# using LINQ&quot; href=&quot;http://ps-a.blogspot.com/2011/08/adding-xml-strings-in-c-using-linq.html&quot; target=&quot;_blank&quot;&gt;Adding xml strings in C# using LINQ&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;In the previous post I showed that LINQ can be used to to manipulate XElements and strings. LINQ managed the transformation between the classes.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;result =&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x1 &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el1&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x2 &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el2&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;select &lt;/span&gt;x1.Substring(0, x1.LastIndexOf(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;&quot;&lt;/span&gt;)) + x2.Substring(x2.IndexOf(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;gt;&quot;&lt;/span&gt;) + 1);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;el1, el2 and the result are XElements and x1, x2 and the object before select are strings.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In the example there are two XElements and the compiler requires that we implement SelectMany. If delete SelectMany we get the following error:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtDsE3RCXYwAnGjidkAOQArPZq-sSseNXwpROT8acxeSJLsIimig2-wA-i23DW5eJCG_wWMbI3pt1Sl0ESjNBoUSgueek0aTHWHTuZo9DYhUYYNLQiY842MsR3QYd7BCAHGnulSr21WRX1/s1600-h/SelectMany%25255B3%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;SelectMany&quot; border=&quot;0&quot; alt=&quot;SelectMany&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBiL-Z9YYsYTjd8plCHCNaLqLslrcczJHnts6DrH1E6h23sDLBRcwaqYmmmfQA6VMw11aPPGNvcRFmp59NR-ltbkqAyD6O7hjTxKKVSikRBCBUinjSsJD9v3aZQXAfVklA2RVZHQzYudOn/?imgmax=800&quot; width=&quot;415&quot; height=&quot;55&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In case we have one XElement we expect that the following will compile:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;private static &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;ToUpper(&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;result =&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;select &lt;/span&gt;x.ToUpper();&lt;br /&gt;&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;It does not: “&#39;System.Xml.Linq.XElement&#39; does not contain a definition for &#39;Select&#39;”&lt;/p&gt;&lt;br /&gt;&lt;p&gt;So we implement Select:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;public static &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;Select(&lt;span style=&quot;color: blue&quot;&gt;this &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el, &lt;span style=&quot;color: #2b91af&quot;&gt;Func&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;&amp;gt; f)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;SelectMany(el, f, (x, y) =&amp;gt; y);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Again it does not compile: “Cannot implicitly convert type &#39;string&#39; to &#39;System.Xml.Linq.XElement&#39;”&lt;/p&gt;&lt;br /&gt;&lt;p&gt;So we add an extra conversion:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;private static &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;ToUpper(&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;result =&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;select &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(x.ToUpper());&lt;br /&gt;&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This time it works:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;el = &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;);&lt;br /&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;ToUpper: {0}&quot;&lt;/span&gt;, ToUpper(el)));&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;Results in:&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCzVkIB6jQnIwTBMsl2ILtehzpOBb1YTPJ44L9eMQzjSfSX884QrFdtbm3Q4zmSMlCKcrzutl_6Wfy3I1oXkv_rnaNe6WH58zySnflAj3K6nS4XOd0n68BHOzn4SoHpEQwxxSmqP_vcljW/s1600-h/ToUpper%25255B2%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;ToUpper&quot; border=&quot;0&quot; alt=&quot;ToUpper&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzqV-yF6GCXUdmDA-gKBt9ABayhySabYkMUSQhYG1-zR5bYXzYeJHzWgqn_a5rnhXSpF5kLG10HP0U0TDnENvBwrNTzCYWlYlR3Ocu6BCQ1aORld50-hyP4TUsKY_6MmpHL1wT3GpKmDH6/?imgmax=800&quot; width=&quot;137&quot; height=&quot;97&quot;&gt;&lt;/a&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;as expected.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Another way to solve the issue is to add a dummy line and use SelectMany:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;private static &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;ToUpper(&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;result =&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;dummy &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;dummy&amp;gt;&amp;lt;/dummy&amp;gt;&quot;&lt;/span&gt;)&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;select &lt;/span&gt;x.ToUpper();&lt;br /&gt;&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;with the same result.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: more information at: &lt;a title=&quot;Projection Operations&quot; href=&quot;http://msdn.microsoft.com/en-us/library/bb546168.aspx&quot; target=&quot;_blank&quot;&gt;http://msdn.microsoft.com/en-us/library/bb546168.aspx&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/6844814476321567107/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/6844814476321567107' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6844814476321567107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6844814476321567107'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/08/difference-between-selectmany-and.html' title='The difference between SelectMany and Select in LINQ'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBiL-Z9YYsYTjd8plCHCNaLqLslrcczJHnts6DrH1E6h23sDLBRcwaqYmmmfQA6VMw11aPPGNvcRFmp59NR-ltbkqAyD6O7hjTxKKVSikRBCBUinjSsJD9v3aZQXAfVklA2RVZHQzYudOn/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-5681719671497892736</id><published>2011-08-07T14:40:00.001+02:00</published><updated>2011-08-07T14:49:01.906+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><category scheme="http://www.blogger.com/atom/ns#" term="Monad"/><title type='text'>Adding xml strings in C# using LINQ</title><content type='html'>&lt;p&gt;This is follow up on my previous blog post:&lt;a title=&quot;Adding xml strings in F# using computation expressions&quot; href=&quot;http://ps-a.blogspot.com/2011/08/adding-xml-strings-in-f-using.html&quot;&gt;Adding xml strings in F# using computation expressions&lt;/a&gt;. The text is nearly identical, the language is C# instead of F#.&lt;/p&gt; &lt;p&gt;In some cases classes are enhanced wrappers of simple classes. For instance in .NET:  &lt;ul&gt; &lt;li&gt;DateTime is a point in time and provides, among others things, extra functionality related to representing date and time formats.  &lt;li&gt;XElement is an xml string and provides, among others things, checks to determine the validity of the xml string.  &lt;li&gt;Option can contain a value and can tell you if there is value available.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Sometimes you have to deal with underling class and reuse some of the functionality of the wrapper. In this case you could consider using &lt;a title=&quot;LINQ&quot; href=&quot;http://msdn.microsoft.com/en-us/netframework/aa904594&quot;&gt;LINQ&lt;/a&gt;. We first define the Return, Bind and SelectMany functions to create the required functions.  &lt;p&gt;For details more details see:  &lt;ul&gt; &lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Functional-Programming-Techniques-Projects-Programmer/dp/0470744588/ref=sr_1_1?ie=UTF8&amp;amp;qid=1312719498&amp;amp;sr=8-1&quot;&gt;Functional Programming in C#: Classic Programming Techniques for Modern Projects (Wrox Programmer to Programmer)&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;http://www.amazon.com/Real-World-Functional-Programming-Examples/dp/1933988924/ref=sr_1_2?ie=UTF8&amp;amp;qid=1312719498&amp;amp;sr=8-2&quot;&gt;Real World Functional Programming: With Examples in F# and C#&lt;/a&gt;  &lt;li&gt;&lt;a href=&quot;http://mikehadlow.blogspot.com/2011/01/monads-in-c1-introduction.html&quot;&gt;Monads in C#–1. Introduction&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;All excellent resources.&lt;/p&gt; &lt;ul&gt; &lt;p&gt;&lt;span style=&quot;color: blue&quot;&gt;public static class&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XmlMonad&lt;br&gt;&lt;/span&gt;{&lt;br&gt;&amp;nbsp; &lt;span style=&quot;color: green&quot;&gt;//monad&lt;br&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;public static&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;Return(&lt;span style=&quot;color: blue&quot;&gt;this string&lt;/span&gt;text)&lt;br&gt;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;try&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(text);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;catch&lt;/span&gt;(&lt;span style=&quot;color: #2b91af&quot;&gt;XmlException &lt;/span&gt;exc)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #2b91af&quot;&gt;String&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;XmlException&amp;gt;{0}&amp;lt;/XmlException&amp;gt;&quot;&lt;/span&gt;, exc.Message));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp; }&lt;br&gt;&lt;br&gt;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;public static&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;Bind(&lt;span style=&quot;color: blue&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el, &lt;span style=&quot;color: #2b91af&quot;&gt;Func&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;&amp;gt; f)&lt;br&gt;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;try&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;return&lt;/span&gt;f(el.ToString());&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;catch&lt;/span&gt;(&lt;span style=&quot;color: #2b91af&quot;&gt;XmlException &lt;/span&gt;exc)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #2b91af&quot;&gt;String&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;XmlException&amp;gt;{0}&amp;lt;/XmlException&amp;gt;&quot;&lt;/span&gt;, exc.Message));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp; }&lt;br&gt;&lt;br&gt;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;public static&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;SelectMany(&lt;span style=&quot;color: blue&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el, &lt;span style=&quot;color: #2b91af&quot;&gt;Func&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;&amp;gt; f, &lt;span style=&quot;color: #2b91af&quot;&gt;Func&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;&amp;gt; select)&lt;br&gt;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue&quot;&gt;return&lt;/span&gt;el.Bind(text =&amp;gt; f(text).Bind(x =&amp;gt; select(text, x).Return()));&lt;br&gt;&amp;nbsp; }&lt;br&gt;}&lt;/p&gt;&lt;/ul&gt;&lt;pre&gt;&lt;font face=&quot;Verdana&quot;&gt;We can now define a add function that will xml elements by using a string manipulation:&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;private static &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;Add(&lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el1, &lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;el2)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: #2b91af&quot;&gt;XElement &lt;/span&gt;result =&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x1 &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el1&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;from &lt;/span&gt;x2 &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;el2&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;select &lt;/span&gt;x1.Substring(0, x1.LastIndexOf(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;&quot;&lt;/span&gt;)) + x2.Substring(x2.IndexOf(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;gt;&quot;&lt;/span&gt;) + 1);&lt;br /&gt;&lt;br /&gt;  &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font face=&quot;Verdana&quot;&gt;Add in action:&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;el1 = &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;);&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;el2 = &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;Add: {0}&quot;&lt;/span&gt;, Add(el1,el2)));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Results in:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmjBDEwx4VdyNep4n-dQbhlGFW6u1LSzLrfNaXneu8hNI-6Mvu3d0oDaKWTgA109Fuy3Ll0aB0H6uwAcXAPhbRUKYqxCLoROk2EDjXzlSIAWEVUC9iSj0zCOmImo7AhxAayRG4ol2d3K4/s1600-h/AddInAction%25255B2%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;AddInAction&quot; border=&quot;0&quot; alt=&quot;AddInAction&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhChBVaRlpDceXMh5MuqLx9sQAg-f1drXGZogtGdWill2pWQKj6BE3iXeCRa15Bos5l-LwcHoo1-5-Cuh_61Ilsp9SK4BYgoc85-xhDWyIANyUv-SAb1eh0-r3zKnKn1Q-994rsHG08DsUn/?imgmax=800&quot; width=&quot;169&quot; height=&quot;103&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;When we change the xml into:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;el2 = &lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;.Parse(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;c&amp;gt;&amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;&amp;lt;/c&amp;gt;&quot;&lt;/span&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The result is:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNQLRBYS3lxPq82DBsyWw8SeEBA4JC-Uh5efejVUE-kQJC_WmbE3cc06DLeRkjWanjyEXbUOsvl-qL_e01x6pcReYRBY6UkyqYMl9UQIUxVFUwcSpzrz7VaQX1838RN6BsMPww5z_sMjd5/s1600-h/AddInActionException%25255B3%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;AddInActionException&quot; border=&quot;0&quot; alt=&quot;AddInActionException&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE49qHR_JxLB12T6duFzZq7I6xDJGlKm6sx3X6xNcDK4uxbRO6tmGWU4mKjqPl4aLgsGUhjuvyWQU1c6fpVAEVx7ojfQCd6MRykoN2FbmvlcKIgBuyiqVHkfnapEilHhsWk49cj-eZgl_W/?imgmax=800&quot; width=&quot;430&quot; height=&quot;54&quot;&gt;&lt;/a&gt;&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/5681719671497892736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/5681719671497892736' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/5681719671497892736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/5681719671497892736'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/08/adding-xml-strings-in-c-using-linq.html' title='Adding xml strings in C# using LINQ'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhChBVaRlpDceXMh5MuqLx9sQAg-f1drXGZogtGdWill2pWQKj6BE3iXeCRa15Bos5l-LwcHoo1-5-Cuh_61Ilsp9SK4BYgoc85-xhDWyIANyUv-SAb1eh0-r3zKnKn1Q-994rsHG08DsUn/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-1600666697942088065</id><published>2011-08-04T15:19:00.001+02:00</published><updated>2011-08-07T14:41:13.176+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Monad"/><title type='text'>Adding xml strings in F# using computation expressions</title><content type='html'>&lt;p&gt;In some cases types are enhanced wrappers of simple types. For instance in .NET:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;DateTime is a point in time and provides, among others things, extra functionality related to representing date and time formats.  &lt;li&gt;XElement is an xml string and provides, among others things, checks to determine the validity of the xml string.  &lt;li&gt;Option can contain a value and can tell you if there is value available.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Sometimes you have to deal with underling type and reuse some of the functionality of the wrapper. In this case you could consider using &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd233182.aspx&quot; target=&quot;_blank&quot;&gt;computation expressions&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;This is a simple xml example. We create a xmlBuilder and reuse the validation logic of XElement:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.Xml&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.Xml.Linq&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;type &lt;/span&gt;xmlBuilder()=&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;x.Bind(el:XElement,(f:string &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;XElement)) =&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;try&lt;br /&gt;            &lt;/span&gt;f(el.ToString())&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;with&lt;br /&gt;            &lt;/span&gt;| :? XmlException &lt;span style=&quot;color: blue&quot;&gt;as &lt;/span&gt;exc &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;XElement.Parse(String.Format(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;XmlException&amp;gt;{0}&amp;lt;/XmlException&amp;gt;&quot;&lt;/span&gt;, exc.Message))&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;x.Return(text) = &lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;try&lt;br /&gt;            &lt;/span&gt;XElement.Parse(text)&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;with&lt;br /&gt;            &lt;/span&gt;| :? XmlException &lt;span style=&quot;color: blue&quot;&gt;as &lt;/span&gt;exc &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;XElement.Parse(String.Format(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;XmlException&amp;gt;{0}&amp;lt;/XmlException&amp;gt;&quot;&lt;/span&gt;, exc.Message))&lt;br /&gt;&lt;br /&gt;The string “123” creates an error:&lt;/pre&gt;&lt;span style=&quot;color: green&quot;&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;xml = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;xmlBuilder()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;error =&lt;br /&gt;    xml { &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: maroon&quot;&gt;&quot;123&quot;&lt;br /&gt;        &lt;/span&gt;}&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;val error : XElement = &amp;lt;XmlException&amp;gt;Data at the root level is invalid. Line 1, position 1.&amp;lt;/XmlException&amp;gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;The expression can now be used to reuse sting functions:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;toUpper el =&lt;br /&gt;    xml { &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = el&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x.ToUpper()&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;el = XElement.Parse(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result1 = el |&amp;gt; toUpper &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;val result1 : XElement = &amp;lt;A&amp;gt;&lt;br /&gt;  &amp;lt;B&amp;gt;1&amp;lt;/B&amp;gt;&lt;br /&gt;  &amp;lt;B&amp;gt;2&amp;lt;/B&amp;gt;&lt;br /&gt;&amp;lt;/A&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In the same way we can define a simple add function for xml:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;(+) (el1:XElement) (el2:XElement) =&lt;br /&gt;    xml { &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x1 = el1&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x2 = el2&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x1.Substring(0, x1.LastIndexOf(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;&quot;&lt;/span&gt;)) + x2.Substring(x2.IndexOf(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;gt;&quot;&lt;/span&gt;) + 1)&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;el1 = XElement.Parse(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;el2 = XElement.Parse(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result2 = el1 + el2&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;val result2 : XElement =&lt;br /&gt;  &amp;lt;a&amp;gt;&lt;br /&gt;  &amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&lt;br /&gt;  &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&lt;br /&gt;  &amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;&lt;br /&gt;  &amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;&lt;br /&gt;&amp;lt;/a&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;el3 = XElement.Parse(&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;c&amp;gt;&amp;lt;b&amp;gt;3&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;4&amp;lt;/b&amp;gt;&amp;lt;/c&amp;gt;&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result3 = el1 + el3&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;val result3 : XElement = &amp;lt;XmlException&amp;gt;The &#39;a&#39; start tag on line 1 position 2 does not match the end tag of &#39;c&#39;. Line 7, position 3.&amp;lt;/XmlException&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;This may not be in line with the concept of information hiding, but it can help you in case you have to deal with the simple type to get the work done.&lt;/pre&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/1600666697942088065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/1600666697942088065' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/1600666697942088065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/1600666697942088065'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/08/adding-xml-strings-in-f-using.html' title='Adding xml strings in F# using computation expressions'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-442148023738438298</id><published>2011-07-14T15:05:00.001+02:00</published><updated>2011-07-14T15:05:10.625+02:00</updated><title type='text'>What is the USP of the monad?</title><content type='html'>&lt;p&gt;I am preparing an introductory article on monads for a Dutch software magazine. It is intended for .NET developers. I have to restrict myself so I am looking for the Unique Selling Point (USP) of the monad.&lt;/p&gt; &lt;p&gt;This is the list of selling points I could find. I left out selling points of specific monads and used the formulation of &lt;a href=&quot;http://en.wikipedia.org/wiki/Monad_(functional_programming)&quot; target=&quot;_blank&quot;&gt;Wikipedia&lt;/a&gt;: &lt;ol&gt; &lt;li&gt;Monads are a kind of abstract data type constructor that encapsulate program logic instead of data in the domain model.&lt;/li&gt; &lt;li&gt;Control structure/inspection.&lt;/li&gt; &lt;li&gt;Hiding complexity with syntactic sugar.&lt;/li&gt; &lt;li&gt;Composition : monads chain actions together to build a pipeline.&lt;/li&gt; &lt;li&gt;To express input/output (I/O) operations and changes in state without using language features that introduce side effects.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;I put them in the order of most favorite to least favorite. &lt;p&gt;&lt;strong&gt;My remarks&lt;/strong&gt;: &lt;p&gt;1. Monads are a kind of abstract data type constructor that encapsulate program logic instead of data in the domain model. &lt;p&gt;This point can be split into two aspects of monads: &lt;ol&gt; &lt;li&gt;The monadic type is a wrapper of a data type (If M is the name of the monad and t is a data type, then &quot;M t&quot; is the corresponding type in the monad).&lt;/li&gt; &lt;li&gt;The functions: read (unit) and bind.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;I think that the ability to have both access to the functionality of the wrapper and the original data type and a way to transform solution between the two is the most valuable selling point. &lt;p&gt;2. Control structure/inspection. &lt;p&gt;The monad is an excellent way to encapsulate inspection logic. Most monad tutorials start with the maybe monad because it is a simple example. It also shows the value of the monadic approach by hiding inspection plumbing. &lt;p&gt;3. Hiding complexity with syntactic sugar. &lt;p&gt;I think that the popularity of LINQ in C# and VB.NET is a proof that hiding complexity with syntactic sugar has its value. &lt;p&gt;4. Composition: monads chain actions together to build a pipeline. &lt;p&gt;In &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd233182.aspx&quot; target=&quot;_blank&quot;&gt;F# computation expressions&lt;/a&gt; or monads are also described as workflows. So this could be the USP. Sequence expression are a proof of the value of composition. &lt;p&gt;5. To express input/output (I/O) operations and changes in state without using language features that introduce side effects. &lt;p&gt;This is the least relevant point for a .NET developer. I do understand that this the most relevant one for a developer in a pure language or one that want to reduce the number of side effects. &lt;p&gt;Please feel free to add a command in case I missed a selling point or you have a better way to order the them.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/442148023738438298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/442148023738438298' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/442148023738438298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/442148023738438298'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/07/what-is-usp-of-monad.html' title='What is the USP of the monad?'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-6297306168888818859</id><published>2011-06-28T19:59:00.001+02:00</published><updated>2011-06-29T20:41:36.144+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Monad"/><title type='text'>WTF is a Monad by Robert C. Martin in F#</title><content type='html'>&lt;p&gt;I have read some material describing &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd233182.aspx&quot;&gt;Computation Expressions&lt;/a&gt; and knew computation expressions are the F# implementation of monads, but I did know why one should use a monad.  &lt;p&gt;A few days ago saw the video of presentation by &lt;a href=&quot;http://www.objectmentor.com/omTeam/martin_r.html&quot; target=&quot;_blank&quot;&gt;Robert C. Martin&lt;/a&gt; (Uncle Bob) at the &lt;a href=&quot;http://www.ndc2011.no/&quot;&gt;Norwegian Developers Conference&lt;/a&gt; called “&lt;a href=&quot;http://ndc2011.macsimum.no/SAL7/Torsdag/1140-1240.wmv&quot;&gt;WTF is a Monad&lt;/a&gt;” and now it makes sense to me.  &lt;p&gt;It is a proven way of solving problems. If you:  &lt;ul&gt; &lt;li&gt;have a problem in one domain  &lt;li&gt;you can transform it to another domain  &lt;li&gt;solve the problem in the other domain  &lt;li&gt;and can transform it back&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;you have a solution.  &lt;p&gt;I have translated some of the code of the presentation to F#. I tried to stay as close to the original code as possible and did not do much refactoring. I skipped the last two examples (distributions an state).  &lt;p&gt;Update:&lt;strike&gt; I did not implement the examples that required lift. I have not figured out how to do that.&lt;/strike&gt; I have created the lift myself (details: &lt;a title=&quot;http://bugsquash.blogspot.com/2010/12/notes-on-haskell-functors-and-f.html&quot; href=&quot;http://bugsquash.blogspot.com/2010/12/notes-on-haskell-functors-and-f.html&quot; target=&quot;_blank&quot;&gt;http://bugsquash.blogspot.com/2010/12/notes-on-haskell-functors-and-f.html&lt;/a&gt;) &lt;p&gt;I like to thank Robert for the permission to share the code. Feel free to add improvements in the comments.&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//Non-Monadic dots&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;dotsToN (d:string) =&lt;br /&gt;    d.Length&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result1 = dotsToN &lt;span style=&quot;color: maroon&quot;&gt;&quot;.....&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;nToDots (n:int) =&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;string(&lt;span style=&quot;color: maroon&quot;&gt;&#39;.&#39;&lt;/span&gt;, n)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result2 = nToDots 5&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;addDots da db =&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;a = dotsToN da&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;b = dotsToN db&lt;br /&gt;    nToDots (a+b)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result3 = addDots &lt;span style=&quot;color: maroon&quot;&gt;&quot;...&quot; &quot;...&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;//Monadic dots&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;dotResult = nToDots&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;dotBind d (f:int &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;string) =&lt;br /&gt;    d |&amp;gt; dotsToN |&amp;gt; f&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;addDots&#39; da db =&lt;br /&gt;    dotBind da (&lt;span style=&quot;color: blue&quot;&gt;fun &lt;/span&gt;a &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt;&lt;br /&gt;        &lt;/span&gt;dotBind db (&lt;span style=&quot;color: blue&quot;&gt;fun &lt;/span&gt;b &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt;&lt;br /&gt;            &lt;/span&gt;dotResult (a + b)))&lt;br /&gt;    &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result4= addDots&#39; &lt;span style=&quot;color: maroon&quot;&gt;&quot;...&quot; &quot;...&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;//dot-Monad&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;type &lt;/span&gt;dotBuilder()=&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;x.Bind(d,(f:int &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;string)) = d |&amp;gt; dotsToN |&amp;gt; f&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;x.Return(n) = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;string(&lt;span style=&quot;color: maroon&quot;&gt;&#39;.&#39;&lt;/span&gt;, n)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;dot = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;dotBuilder()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;addDots&#39;&#39; da db =&lt;br /&gt;    dot { &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = da&lt;br /&gt;          &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;y = db&lt;br /&gt;          &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x + y&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result5= addDots&#39;&#39; &lt;span style=&quot;color: maroon&quot;&gt;&quot;...&quot; &quot;...&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;multiplyDots da db =&lt;br /&gt;    dot { &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = da&lt;br /&gt;          &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;y = db&lt;br /&gt;          &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x*y&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result6= multiplyDots &lt;span style=&quot;color: maroon&quot;&gt;&quot;...&quot; &quot;...&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;dcd dt du =&lt;br /&gt;    dot { &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;tens = dt&lt;br /&gt;          &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;units = du&lt;br /&gt;          &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;(10 * tens + units)&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result7= dcd &lt;span style=&quot;color: maroon&quot;&gt;&quot;...&quot; &quot;.....&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;// In Clojure the monad gets the lift for free&lt;br /&gt;// In F# we have to create it ourselves&lt;br /&gt;// More info: &lt;a href=&quot;http://bugsquash.blogspot.com/2010/12/notes-on-haskell-functors-and-f.html&quot; target=&quot;_blank&quot;&gt;http://bugsquash.blogspot.com/2010/12/notes-on-haskell-functors-and-f.html&lt;/a&gt; --&lt;br /&gt;//&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;liftDots_1 f a1 = &lt;br /&gt;    dot { &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x1 = a1 &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;f x1 &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;liftDots_2 f a1 a2 = &lt;br /&gt;    dot { &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x1 = a1&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x2 = a2&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;f x1 x2&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;liftDots_4 f a1 a2 a3 a4 = &lt;br /&gt;    dot { &lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x1 = a1&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x2 = a2&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x3 = a3&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x4 = a4&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;f x1 x2 x3 x4&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;substractDots = liftDots_2 (-)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result7a= substractDots &lt;span style=&quot;color: maroon&quot;&gt;&quot;.....&quot; &quot;..&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;mean4 a b c d = (a+b+c+d)/4&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;dmean4 = liftDots_4 mean4&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result7b= dmean4 &lt;span style=&quot;color: maroon&quot;&gt;&quot;...&quot; &quot;..&quot; &quot;...&quot; &quot;....&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;//&lt;br /&gt;//complex number (inspection)&lt;br /&gt;//&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.Numerics&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;c_0 = Complex.Zero&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;c_1 = Complex.One&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;c_i = Complex.ImaginaryOne&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;type &lt;/span&gt;complexBuilder()=&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;b.Return(x:float) = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;Complex(x,0.0) &lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;b.Bind((c:Complex),(f:float &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;Complex)) = &lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;if &lt;/span&gt;c.Imaginary = 0.0 &lt;span style=&quot;color: blue&quot;&gt;then&lt;br /&gt;            &lt;/span&gt;f c.Real&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;else &lt;br /&gt;            &lt;/span&gt;failwithf &lt;span style=&quot;color: maroon&quot;&gt;&quot;Imaginary&quot;&lt;br /&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;complex = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;complexBuilder()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;addComplex c1 c2 =&lt;br /&gt;    complex { &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = c1&lt;br /&gt;              &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;y = c2&lt;br /&gt;              &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x + y&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result8= addComplex c_1 c_1;;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result9= addComplex c_1 c_i;; &lt;span style=&quot;color: green&quot;&gt;//System.Exception: Imaginary&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result10= addComplex c_i c_i;; &lt;span style=&quot;color: green&quot;&gt;//System.Exception: Imaginary&lt;br /&gt;&lt;br /&gt;//null&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;type &lt;/span&gt;noNullBuilder()=&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;b.Return(mv) = mv &lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;b.Bind(mv,f) = &lt;span style=&quot;color: blue&quot;&gt;if &lt;/span&gt;(mv = &lt;span style=&quot;color: blue&quot;&gt;null&lt;/span&gt;) &lt;span style=&quot;color: blue&quot;&gt;then null else &lt;/span&gt;f mv&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;nuNull = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;noNullBuilder()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;// int can not be null in .Net&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;fragile (a:string) (b:string) (c:string) =&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;if &lt;/span&gt;(a= &lt;span style=&quot;color: blue&quot;&gt;null&lt;/span&gt;||b=&lt;span style=&quot;color: blue&quot;&gt;null&lt;/span&gt;||c=&lt;span style=&quot;color: blue&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;then&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: maroon&quot;&gt;&quot;CRASH&quot;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;else&lt;br /&gt;        &lt;/span&gt;a + b + c&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result11 = fragile &lt;span style=&quot;color: maroon&quot;&gt;&quot;a&quot; &quot;b&quot; &quot;c&quot;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result12 = fragile &lt;span style=&quot;color: maroon&quot;&gt;&quot;a&quot; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;null &lt;/span&gt;&lt;span style=&quot;color: maroon&quot;&gt;&quot;c&quot; &lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;//&quot;CRASH&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;safeFragile (a:string) (b:string) (c:string) =&lt;br /&gt;    nuNull { &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = a&lt;br /&gt;             &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;y = b&lt;br /&gt;             &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;z = c&lt;br /&gt;             &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x + y + z&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result13 = safeFragile &lt;span style=&quot;color: maroon&quot;&gt;&quot;a&quot; &quot;b&quot; &quot;c&quot;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result14 = safeFragile &lt;span style=&quot;color: maroon&quot;&gt;&quot;a&quot; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;null &lt;/span&gt;&lt;span style=&quot;color: maroon&quot;&gt;&quot;c&quot; &lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;//val result14 : string = null&lt;br /&gt;&lt;br /&gt;//List&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;l_a = [1;2;3]&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;l_b = [4;5;6]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;addList = seq {&lt;span style=&quot;color: blue&quot;&gt;for &lt;/span&gt;a &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;l_a &lt;span style=&quot;color: blue&quot;&gt;do&lt;br /&gt;                    for &lt;/span&gt;b &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;l_b &lt;span style=&quot;color: blue&quot;&gt;do &lt;br /&gt;                    yield &lt;/span&gt;a+b&lt;br /&gt;                  }|&amp;gt; Seq.toList&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;multList = seq {&lt;span style=&quot;color: blue&quot;&gt;for &lt;/span&gt;a &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;l_a &lt;span style=&quot;color: blue&quot;&gt;do&lt;br /&gt;                    for &lt;/span&gt;b &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;l_b &lt;span style=&quot;color: blue&quot;&gt;do &lt;br /&gt;                    yield &lt;/span&gt;a*b&lt;br /&gt;                  }|&amp;gt; Seq.toList&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;//helper for the demo&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;flatten l = &lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;let rec &lt;/span&gt;flatten&#39; l result =&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;match &lt;/span&gt;l &lt;span style=&quot;color: blue&quot;&gt;with &lt;br /&gt;        &lt;/span&gt;|[] &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;result&lt;br /&gt;        |h::t &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;flatten&#39; t (h@result)&lt;br /&gt;    flatten&#39; (l|&amp;gt;List.rev) []&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result15 = flatten [[1;2;3];[7;8;9]]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;type &lt;/span&gt;listBuilder()=&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;b.Return(v) = [v]&lt;br /&gt;    &lt;span style=&quot;color: blue&quot;&gt;member &lt;/span&gt;b.Bind(mv,f) = mv |&amp;gt; List.map f |&amp;gt; flatten&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;list = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;listBuilder()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;addList&#39; a b = list {&lt;br /&gt;                       &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = a&lt;br /&gt;                       &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;y = b&lt;br /&gt;                       &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x + y &lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result16 = addList&#39; l_a l_b&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;multList&#39; a b = list {&lt;br /&gt;                       &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;x = a&lt;br /&gt;                       &lt;span style=&quot;color: blue&quot;&gt;let! &lt;/span&gt;y = b&lt;br /&gt;                       &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;x * y &lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result17 = multList&#39; l_a l_b&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;//distribution example see Expert F# of Don Syme page 239..244&lt;br /&gt;//state http://fsharpcode.blogspot.com/2008/12/f-state-monad-type-state-state-state-of.html&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;  </content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/6297306168888818859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/6297306168888818859' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6297306168888818859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/6297306168888818859'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/06/wtf-is-monad-by-robert-c-martin-in-f.html' title='WTF is a Monad by Robert C. Martin in F#'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-1531656007617805563</id><published>2011-06-22T23:24:00.003+02:00</published><updated>2011-06-23T09:14:03.639+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Open XML"/><title type='text'>LINQ to XML, when lazy is too lazy in F# (and C# )</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Today a F# program did not work as expected. This is a small example I created:&lt;/p&gt;&lt;p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;xml =&lt;span style=&quot;color: maroon&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;doc = XDocument.Parse(xml)

&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;getXElements_b (doc:XDocument) =
&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;els = doc.Root.Elements(XName.Get(&lt;span style=&quot;color: maroon&quot;&gt;&quot;b&quot;&lt;/span&gt;))
els&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//test&lt;/span&gt;
&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result1 = doc |&amp;gt; getXElements_b |&amp;gt; Seq.toList
&lt;span style=&quot;color: green&quot;&gt;//val result1 : XElement list = [&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;; &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;]
&lt;span style=&quot;color: green&quot;&gt;//the expected result &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;proces (el:XElement) =
XElement(XName.Get(&lt;span style=&quot;color: maroon&quot;&gt;&quot;c&quot;&lt;/span&gt;)) |&amp;gt; el.ReplaceWith

doc |&amp;gt; getXElements_b |&amp;gt; Seq.iter proces

&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;result2 =  doc.ToString();;
&lt;span style=&quot;color: green&quot;&gt;//val result2 : string = &quot;&amp;lt;a&amp;gt;
//  &amp;lt;c /&amp;gt;
//  &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;
//&amp;lt;/a&amp;gt;&quot;
&lt;/span&gt;&lt;/pre&gt;This is not the expected result. I expected:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;val result2 : string = &quot;&amp;lt;a&amp;gt;
&amp;lt;c /&amp;gt;
&amp;lt;c /&amp;gt;
&amp;lt;/a&amp;gt;&quot;
&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;I can fix it by changing the getXElements_b function:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;getXElements_b (doc:XDocument) =
&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;els = doc.Root.Elements(XName.Get(&lt;span style=&quot;color: maroon&quot;&gt;&quot;b&quot;&lt;/span&gt;)) |&amp;gt; &lt;strong&gt;Seq.toList&lt;/strong&gt;
els
&lt;/pre&gt;&lt;br /&gt;
With this adjustment everything works fine. It seems that I have to force the the computation.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;This is a problem in C# too.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;private void &lt;/span&gt;GetXml()
{
&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;xml = &lt;span style=&quot;color: #a31515&quot;&gt;&quot;&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;1&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;;
&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;doc = &lt;span style=&quot;color: #2b91af&quot;&gt;XDocument&lt;/span&gt;.Parse(xml);
&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;els = doc.Root.Elements(&lt;span style=&quot;color: #2b91af&quot;&gt;XName&lt;/span&gt;.Get(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;b&quot;&lt;/span&gt;));

&lt;span style=&quot;color: blue&quot;&gt;foreach &lt;/span&gt;(&lt;span style=&quot;color: blue&quot;&gt;var &lt;/span&gt;el &lt;span style=&quot;color: blue&quot;&gt;in &lt;/span&gt;els)
{
el.ReplaceWith(&lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;XElement&lt;/span&gt;(&lt;span style=&quot;color: #2b91af&quot;&gt;XName&lt;/span&gt;.Get(&lt;span style=&quot;color: #a31515&quot;&gt;&quot;c&quot;&lt;/span&gt;)));
}

txtResult.Text = doc.ToString();
}&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;produces:&lt;/pre&gt;&lt;br /&gt;
&lt;p&gt;&amp;lt;a&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;c /&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/a&amp;gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;When I step with the debuger through the code the foreach is only one time triggered.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;With support of Google I found the following document:&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb308960.aspx&quot; target=&quot;_blank&quot;&gt;http://msdn.microsoft.com/en-us/library/bb308960.aspx&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilyVyw9rhBFzFDEo7oNiYGKtQ0-XHpkAkA9E2Ao6UA22XJNQNQtUaXDgUgbXzTfhpnfQtbHne6S6sB4MBZmB7p55jfrD8P1TdeiW5nD4XonjiN8LCUnInilrZ7pqM7Jgi5ua83iQxDtUCb/s1600-h/lazyXML%25255B4%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;lazyXML&quot; border=&quot;0&quot; alt=&quot;lazyXML&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpPFg0MZ9xxzCbXr3IE0oqKEDTowxKgtkH5XA-vtXC9aHztxSmlMenRPybhUnNtNhKxjTJTc0xwmYIFABIvfvSYcFlDSsmZhGchoBkrlovNGOE5B72l8SBJjZL6-Zo5NkJQz1ntkbpEBDe/?imgmax=800&quot; width=&quot;710&quot; height=&quot;608&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;You can learn something new everyday.&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;Interesting links:&lt;br /&gt;
&lt;p&gt;The &quot;Halloween Problem&quot; for XML APIs:&lt;br /&gt;
&lt;p&gt;&lt;a title=&quot;http://blogs.msdn.com/b/mikechampion/archive/2006/07/20/672208.aspx&quot; href=&quot;http://blogs.msdn.com/b/mikechampion/archive/2006/07/20/672208.aspx&quot; target=&quot;_blank&quot;&gt;http://blogs.msdn.com/b/mikechampion/archive/2006/07/20/672208.aspx&lt;/a&gt;&lt;br /&gt;
&lt;p&gt;Query Composition using Functional Programming Techniques in C# 3.0:&lt;br /&gt;
&lt;p&gt;&lt;a href=&quot;http://blogs.msdn.com/b/ericwhite/archive/2006/10/04/fp-tutorial.aspx&quot; target=&quot;_blank&quot;&gt;http://blogs.msdn.com/b/ericwhite/archive/2006/10/04/fp-tutorial.aspx&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/1531656007617805563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/1531656007617805563' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/1531656007617805563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/1531656007617805563'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/06/linq-to-xml-when-lazy-is-too-lazy-in-f.html' title='LINQ to XML, when lazy is too lazy in F# (and C# )'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpPFg0MZ9xxzCbXr3IE0oqKEDTowxKgtkH5XA-vtXC9aHztxSmlMenRPybhUnNtNhKxjTJTc0xwmYIFABIvfvSYcFlDSsmZhGchoBkrlovNGOE5B72l8SBJjZL6-Zo5NkJQz1ntkbpEBDe/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-1263152930152493151</id><published>2011-06-20T22:13:00.002+02:00</published><updated>2011-06-21T10:25:08.190+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><category scheme="http://www.blogger.com/atom/ns#" term="Open XML"/><category scheme="http://www.blogger.com/atom/ns#" term="Word"/><category scheme="http://www.blogger.com/atom/ns#" term="XDocument"/><title type='text'>Update an open XML word document in F#</title><content type='html'>&lt;pre class=&quot;code&quot;&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;/font&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font face=&quot;Verdana&quot;&gt;I have created a small function in F# to update the content of a word document.&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//reference to the package 
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;#r &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;span style=&quot;color: maroon&quot;&gt;&lt;font size=&quot;1&quot; face=&quot;Verdana&quot;&gt;&quot;WindowsBase&quot;
&lt;/font&gt;&lt;/span&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//reference to the Xml and Linq 
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;#r &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: maroon&quot;&gt;&quot;System.Xml&quot;
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;#r &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: maroon&quot;&gt;&quot;System.Xml.Linq&quot;

&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System
&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.IO
&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.IO.Packaging
&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.Xml
&lt;span style=&quot;color: blue&quot;&gt;open &lt;/span&gt;System.Xml.Linq

&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//helper to create XName with a namespace
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;xname str =
XName.Get(str, &lt;span style=&quot;color: maroon&quot;&gt;&quot;http://schemas.openxmlformats.org/wordprocessingml/2006/main&quot;&lt;/span&gt;)

&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;// the main function 
// changeDoc copies a word .docx document and updates the content by changing the xml that represents the content
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;changeDoc oldPath newPath (updateDocument:XDocument &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;XDocument) =
&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//update the package part
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;updatePart (part:PackagePart) =
using (part.GetStream(FileMode.Open, FileAccess.Read)) (&lt;span style=&quot;color: blue&quot;&gt;fun &lt;/span&gt;stream &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; 
let &lt;/span&gt;xDocumentOut = stream |&amp;gt; XDocument.Load |&amp;gt; updateDocument
xDocumentOut.Save(part.GetStream(FileMode.Create, FileAccess.Write))
)

File.Copy(oldPath, newPath, &lt;span style=&quot;color: blue&quot;&gt;true&lt;/span&gt;)
using (Package.Open(newPath, FileMode.Open, FileAccess.ReadWrite)) (&lt;span style=&quot;color: blue&quot;&gt;fun &lt;/span&gt;package &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;-&amp;gt;
let &lt;/span&gt;uri = &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;Uri(&lt;span style=&quot;color: maroon&quot;&gt;&quot;/word/document.xml&quot;&lt;/span&gt;, UriKind.Relative )

uri |&amp;gt; package.GetPart|&amp;gt; updatePart
)

&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;// test function to update the document
// adds &quot;_test&quot; to every text  in the document.
&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;let &lt;/span&gt;updateText (xDoc:XDocument) =
&lt;span style=&quot;color: maroon&quot;&gt;&quot;t&quot; &lt;/span&gt;|&amp;gt; xname  |&amp;gt; xDoc.Descendants |&amp;gt; Seq.iter (&lt;span style=&quot;color: blue&quot;&gt;fun &lt;/span&gt;x &lt;span style=&quot;color: blue&quot;&gt;-&amp;gt; &lt;/span&gt;x.Value &amp;lt;- x.Value + &lt;span style=&quot;color: maroon&quot;&gt;&quot;_test&quot;&lt;/span&gt;)
xDoc

&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span style=&quot;color: green&quot;&gt;//test
&lt;/span&gt;changeDoc &lt;span style=&quot;color: maroon&quot;&gt;@&quot;D:\Tmp\test.docx&quot; @&quot;D:\Tmp\test_copy.docx&quot; &lt;/span&gt;updateText;;
&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;font size=&quot;2&quot;&gt;Before &lt;span style=&quot;color: maroon&quot;&gt;&quot;D:\Tmp\test.docx&quot;&lt;/span&gt;:&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font size=&quot;1&quot; face=&quot;Verdana&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJCbGebSdO4hlWsoW4wl9tLSWG6A0zaFzlLlvPd-laSPHg8ziY6D0Oq35waLORVLckrTFRw3PV_z1NLR7UHJMHrKQ9f64oqEnkESVEo4Scfw-2uf6R9WA_PInJ5CQBFAEBzinAca9ExDCx/s1600-h/before%25255B2%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;before&quot; border=&quot;0&quot; alt=&quot;before&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2LbfeZpyjPZXA0-6eE558XrN9Mbm8OuVHqvB9okCGelekJGBvEV9WFwxLCvxQc9RX2LBbgqAQJn7y3BgsdRL9tzmilr5ZBbTaYgCt62Br6jqmNmNkQ0sEAKIZmW-jgXMxKPP-ZCHUwLcy/?imgmax=800&quot; width=&quot;244&quot; height=&quot;243&quot;&gt;&lt;/a&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font face=&quot;Verdana&quot;&gt;&lt;/font&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;font size=&quot;2&quot; face=&quot;Verdana&quot;&gt;After &quot;D:\Tmp\test_copy.docx&quot;:&lt;/font&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhsKzjAplhb6QSt0lG1oybcfLYHOONM9hnnoS7ZZAyKHoRZu3q4PGduhiNNEcMju8-rXP4Pqa3Cw2UYEFLK0feXVQ0U9CErrn5esdcjhBGdmLBU4x4wIjHw65_lFzFt2tjl-CwHkefGqlj/s1600-h/after%25255B2%25255D.jpg&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;after&quot; border=&quot;0&quot; alt=&quot;after&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb0hJ2E2cAMiWuSkBfr95C6hr_rhEuFzuhOTFKhdFmhc82WXlAMloBGWnPV_9c2dxfsgVQ730jA8HZ8GyhkgBbDN3jvIiQWEy6TtLxCWDkKyqOfZAMGWGc8W6SjQsVEof5_UJSHjDsawIi/?imgmax=800&quot; width=&quot;225&quot; height=&quot;206&quot;&gt;&lt;/a&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/1263152930152493151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/1263152930152493151' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/1263152930152493151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/1263152930152493151'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/06/update-open-xml-word-document-in-f.html' title='Update an open XML word document in F#'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2LbfeZpyjPZXA0-6eE558XrN9Mbm8OuVHqvB9okCGelekJGBvEV9WFwxLCvxQc9RX2LBbgqAQJn7y3BgsdRL9tzmilr5ZBbTaYgCt62Br6jqmNmNkQ0sEAKIZmW-jgXMxKPP-ZCHUwLcy/s72-c?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6810762626202656454.post-2186532920755375197</id><published>2011-06-16T11:31:00.009+02:00</published><updated>2011-06-18T09:25:40.606+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# blogs</title><content type='html'>These are the F# blogs I am following:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://tomasp.net/blog/rss.aspx&quot; target=&quot;_blank&quot;&gt;http://tomasp.net/blog/rss.aspx&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://feeds.feedburner.com/bugsquash&quot; target=&quot;_blank&quot;&gt;http://feeds.feedburner.com/bugsquash&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://feeds.feedburner.com/Devhawk&quot; target=&quot;_blank&quot;&gt;http://feeds.feedburner.com/Devhawk&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://feeds.feedburner.com/DidItWithDotNet&quot; target=&quot;_blank&quot;&gt;http://feeds.feedburner.com/DidItWithDotNet&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/dsyme/rss.xml&quot; target=&quot;_blank&quot;&gt;http://blogs.msdn.com/dsyme/rss.xml&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://fsharpnews.blogspot.com/feeds/posts/default&quot; target=&quot;_blank&quot;&gt;http://fsharpnews.blogspot.com/feeds/posts/default&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cs.hubfs.net/blogs/MainFeed.aspx&quot; target=&quot;_blank&quot;&gt;http://cs.hubfs.net/blogs/MainFeed.aspx&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://jyliao.blogspot.com/feeds/posts/default&quot; target=&quot;_blank&quot;&gt;http://jyliao.blogspot.com/feeds/posts/default&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/jomo_fisher/rss.xml&quot; target=&quot;_blank&quot;&gt;http://blogs.msdn.com/jomo_fisher/rss.xml&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/lukeh/rss.xml&quot; target=&quot;_blank&quot;&gt;http://blogs.msdn.com/lukeh/rss.xml&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://feeds.feedburner.com/MatthewPodwysockisBlog&quot; target=&quot;_blank&quot;&gt;http://feeds.feedburner.com/MatthewPodwysockisBlog&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://lepensemoi.free.fr/index.php/feed&quot; target=&quot;_blank&quot;&gt;http://lepensemoi.free.fr/index.php/feed&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://feeds.feedburner.com/planet_fsharp?format=xml&quot; target=&quot;_blank&quot;&gt;http://feeds.feedburner.com/planet_fsharp?format=xml&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://ps-a.blogspot.com/&quot; target=&quot;_blank&quot;&gt;http://ps-a.blogspot.com/&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://strangelights.com/blog/&quot; target=&quot;_blank&quot;&gt;http://strangelights.com/blog/&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cs.hubfs.net/blogs/thepopeofthehub/&quot; target=&quot;_blank&quot;&gt;http://cs.hubfs.net/blogs/thepopeofthehub/&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.achrissmith.com/&quot; target=&quot;_blank&quot;&gt;http://blog.achrissmith.com&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://litemedia.info/&quot; target=&quot;_blank&quot;&gt;http://litemedia.info/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://moiraesoftware.com/&quot; target=&quot;_blank&quot;&gt;http://Moiraesoftware.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://richardminerich.com/&quot; target=&quot;_blank&quot;&gt;http://RichardMinerich.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.intellifactory.com/blogs/rss/F!sharp!/&quot; target=&quot;_blank&quot;&gt;http://www.intellifactory.com/blogs/rss/F!sharp!/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.danielmohl.com/&quot; target=&quot;_blank&quot;&gt;http://blog.danielmohl.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://hestia.typepad.com/flatlander/&quot; target=&quot;_blank&quot;&gt;http://hestia.typepad.com/flatlander/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://sharp-gamedev.blogspot.com/&quot; target=&quot;_blank&quot;&gt;http://sharp-gamedev.blogspot.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.decoratorpattern.com/&quot; target=&quot;_blank&quot;&gt;http://blog.decoratorpattern.com/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
Please add a comment when your blog is missing.</content><link rel='replies' type='application/atom+xml' href='http://ps-a.blogspot.com/feeds/2186532920755375197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/6810762626202656454/2186532920755375197' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/2186532920755375197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6810762626202656454/posts/default/2186532920755375197'/><link rel='alternate' type='text/html' href='http://ps-a.blogspot.com/2011/06/f-blogs.html' title='F# blogs'/><author><name>Piet Amersfoort</name><uri>http://www.blogger.com/profile/10536068168999188614</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Ji4RIpWEtATh1qT5IeqlZ4pGuMiAkXpYYzTYWTwtAC48rjL1lGWN32EF6YsjGo3haWyVJexgszVPfz54jmOzarISvhvdhXzxnCH5lQ0saziOrI-fF10CHAHQCD4qfw/s113/PietAmersfoort.JPG'/></author><thr:total>6</thr:total></entry></feed>