Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 660055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:06:51+00:00 2026-05-13T23:06:51+00:00

I am currently learning F# and functional programming in general (from a C# background)

  • 0

I am currently learning F# and functional programming in general (from a C# background) and I have a question about using .net CLR objects during my processing.

The best way to describe my problem will be to give an example:

let xml = new XmlDocument() 
            |> fun doc -> doc.Load("report.xml"); doc

let xsl = new XslCompiledTransform()
            |> fun doc -> doc.Load("report.xsl"); doc

let transformedXml = 
    new MemoryStream()
        |> fun mem -> xsl.Transform(xml.CreateNavigator(), null, mem); mem

This code transforms an XML document with an XSLT document using .net objects.
Note XslCompiledTransform.Load works on an object, and returns void.
Also the XslCompiledTransform.Transform requires a memorystream object and returns void.

The above strategy used is to add the object at the end (the ; mem) to return a value and make functional programming work.

When we want to do this one after another we have a function on each line with a return value at the end:

let myFunc = 
  new XmlDocument("doc")
   |> fun a -> a.Load("report.xml"); a
   |> fun a -> a.AppendChild(new XmlElement("Happy")); a

Is there a more correct way (in terms of functional programming) to handle .net objects and objects that were created in a more OO environment?

The way I returned the value at the end then had inline functions everywhere feels a bit like a hack and not the correct way to do this.

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:06:51+00:00Added an answer on May 13, 2026 at 11:06 pm

    One of the great benefits of F# is that it allows you to mix the functional programming style with other styles (namely object-oriented and imperative). Since most of the .NET libraries are object-oriented and imperative, the best way to access .NET functionality from F# is to simply use the imperative features of F#. This means that when working with .NET objects, the idiomatical F# code will look almost like C#.

    EDIT: The following slightly modified example shows how to wrap XSL transformation into a function that takes the name of the input file and a name of the xsl file. It returns the MemoryStream where the output was written:

    let transformDocument inputFile xslFile =
      let doc = new XmlDocument()  
      doc.Load(inputFile)
      let xsl = new XslCompiledTransform() 
      xsl.Load(xslFile)
    
      let mem = new MemoryStream() 
      xsl.Transform(xml.CreateNavigator(), null, mem)
      mem
    

    And the second example:

    let doc = new XmlDocument("doc")   
    doc.Load("report.xml")
    doc.AppendNode(new XmlElement("Happy"))
    

    This doesn’t mean that you’re turning away from the functional style in any way – there are many opportunities to use functional style when working with .NET classes. For example you can use higher-order functions like Seq.filter and Seq.map (or sequence expressions) to process collections of data (or XML elements). You can still write abstractions using higher-order functions.

    The System.Xml namespace is very imperative, so there isn’t much space for functional style. However, the code that generates the data that you store in XML can be fully functional. It may be worth looking at the LINQ to XML classes (in .NET 3.5+), because they are designed in a much more functional-programming-friendly fashion (as they are supposed to work well with LINQ, which is also functional).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Open the site in IE8 Press F12 for developer tools… May 14, 2026 at 4:50 pm
  • Editorial Team
    Editorial Team added an answer In a standard security context, you cannot access data on… May 14, 2026 at 4:50 pm
  • Editorial Team
    Editorial Team added an answer He has a huge backgroundimage on the html tag: html… May 14, 2026 at 4:50 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.