# VBForums CodeBank > CodeBank - Other >  Functional programming (specifically Microsoft F#)

## Peter Swinkels

Hi,

I 've been experimenting with functional programming, Microsoft F# to be specific.

After several hours of trying I finally succeeded in making a small application called "FTextBin" that does more than demonstrate a F# function.

It extracts "human-readable" strings from binary files much like the Linux/Unix strings command. (I wrote something similar in vb6 and vb.net, search the forum for "TextBin".)

To use it:
1. Load and compile it with Microsoft Visual Studio.
2. Start a command line based shell. (Cmd.exe/Power Shell.)
3. Run the executable with the binary file to be searched as a command line argument.
4. It should now dump a list of strings to the standard output.

If an exception occurs during run-time, it will simply display: "Error: "_exception message_".

Normally, I would post something like this in the code bank, but I don't think there's one for F#.

Any way, who else here has experimented and/or has experience  with functional programming?

----------


## FunkyDexter

It does belong in CodeBank really but you're right, there's no natural home for it.  I could move it to CodeBank - Other for you if you'd like.

----------


## Peter Swinkels

> It does belong in CodeBank really but you're right, there's no natural home for it.  I could move it to CodeBank - Other for you if you'd like.


Yes, if you could move it there, I would appreciate it.

----------


## szlamany

I see you are using F# but you are looping and that kind of flies in the face of a functional language.

From what I understand some kind of recursion should take the place of that with the function returning the next spot until some end case is met.

I'm no expert in this - just my two cents!

----------


## Shaggy Hiker

Snuck in and made the move ahead of Funky.

----------


## Peter Swinkels

> I see you are using F# but you are looping and that kind of flies in the face of a functional language.
> 
> From what I understand some kind of recursion should take the place of that with the function returning the next spot until some end case is met.
> 
> I'm no expert in this - just my two cents!


Thanks for your comments.

As far as I understand it F# isn't 100% functional, and for now I don't mind if some traces of imperative style coding creep in my F# code. Trust me, figuring out how to do what I wanted in F# was pretty hard considering I originally learned programming with QBasic  :EEK!:  (and now mostly use VB.Net.) As I understand it, VB.Net supports some degree of functional programming, but both are mostly imperative. What I mean is that I'm already learning by being forced to think ~75% functional when using F#. If any one has any ideas on how to substitute the loop in my code...

----------


## szlamany

The reason I commented was that I am very familiar with JavaScript used in large applications and I've heard that you could use JavaScript in a "functional manner".

I do not try to do that with JavaScript myself.

So I downloaded your app to see what you might be doing.

I'd be interested to see what others might offer also!

----------


## szlamany

This link might help

http://blogs.msdn.com/b/doriancoromp...ile-loops.aspx

----------


## Peter Swinkels

> This link might help
> 
> http://blogs.msdn.com/b/doriancoromp...ile-loops.aspx


Hi, that looks like a useful link. Thanks.

----------


## Peter Swinkels

> Hi, that looks like a useful link. Thanks.


Well, it looks like I managed to replace my loops with recursive functions...


```
//This module's imports and settings.
open System.IO

//This procedure is executed when this program is started.
[<EntryPoint>]
let main argv = 
   try      
      let rec DisplayList (items:List<string>) = 
         printf "%s\n" items.Head
         if items.Length = 1
         then items
         else DisplayList(items.Tail)
      let mutable Texts = ""
      let rec LoopThroughList (items:List<char>) = 
         Texts <- Texts + 
            if items.Head >= ' ' && items.Head <= '~' then items.Head.ToString()
            elif Texts.EndsWith('\u0000'.ToString()) then ""
            else '\u0000'.ToString()
         if items.Length = 1
         then items
         else LoopThroughList(items.Tail)

      File.ReadAllBytes(argv.[0]) |> Array.toList |> List.map char |> LoopThroughList |> ignore
      Texts.Split('\u0000') |> Array.toList |> List.distinct |> DisplayList |> ignore
   with
      | exceptionO -> printf("Error: \"%s\"\n") exceptionO.Message
   0
```

What I don't like about my recursive functions is that in the case of "LoopThroughList" I haven't yet found a way to get it to return a useful return value when it has reached the last list item. I could assign it to the "Texts" variable instead dumping it to "ignore".

----------


## szlamany

Could you push info into an array or is that against the "grain" of functional?

----------


## Peter Swinkels

After a long while I decided to revisit this project. The program is now written in a fully functional style, that is no mutable values or loops.

----------

