Note that there are some explanatory texts on larger screens.

plurals
  1. POUnexpected type compilation issue when using pipe operations in F#
    primarykey
    data
    text
    <p>I am trying to parse a directory of XML files and then select the value of particular attribute if a given node is present. Am not able to understand the reason for the compilation error that the following F# is causing.</p> <pre><code>open System open System.IO open System.Xml open System.Xml.XPath open System.Xml.Linq let configRootDirectory = @"C:\dir" let relativeProductDir = @"relDir" let ExtractConfiguredCalculator (productConfigFile:string) = let xmlNavigator = XPathDocument(productConfigFile).CreateNavigator() let node = xmlNavigator.SelectSingleNode(@"Product/SupportedRisk/Risk[@type='PV']") node.GetAttribute("methodology", "") let configFile = Directory.GetFiles(Path.Combine(configRootDirectory, relativeProductDir), @"*.xml") |&gt; Seq.cast&lt;string&gt; |&gt; Seq.iter(fun configFileName -&gt; ExtractConfiguredCalculator(configFileName)) |&gt; Seq.filter(fun configuredCalculatorNode -&gt; configuredCalculatorNode != null) |&gt; Seq.iter(fun calculator -&gt; Console.WriteLine(calculator)) </code></pre> <p>The above snippet is from the code that I am experimenting with in LinqPad. The error message seen is as below.</p> <pre><code>This expression was expected to have type unit but here has type string </code></pre> <p><strong>Update</strong> Trying to get more f#-ish. Please suggest if something can be improved.</p> <pre><code>let configFile = Directory.GetFiles(Path.Combine(configRootDirectory, relativeProductDir), @"*.xml") |&gt; Seq.map(fun configFileName -&gt; let xmlNavigator = XPathDocument(configFileName).CreateNavigator() let node = xmlNavigator.SelectSingleNode(@"Product/SupportedRisk/Risk[@type='PV']") match node with | null -&gt; "PV not configured" | _ -&gt; let attributeValue = node.GetAttribute("methodology", "") match attributeValue with | null -&gt; "Calculator not configured" | _ -&gt; attributeValue) |&gt; Seq.iter (printfn "%s") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload