Jump to content
  • Advertisement
  • entries
  • comments
  • views

Adventures in F# Part 1

Sign in to follow this  


I finished my first F# app in about 2 hours. No feedback at deadline and it's been pushed off the main page. Alas.

I am a little disappointed so far. Pattern matching, which seems to be one of the big things promoted as functional stuff to learn seems at face value to be not much more than nicer syntax for if/else/switch blocks. Not anything particularly new. I assume I'm just missing some nuance or situation where it is balls out fantastic.

The MSVS integration is okay. Syntax highlighting is sparse, its not really polished, and it wants to label stuff with weird errors a little prematurely. Intellisense is a little quirky, but works pretty well even with type inference everywhere. Most importantly, it works with little focus to the underlying bits and with consistency. Now if they could just make the intellisense case insensitive like it is with other languages and I'll be happy.

The language itself is okay I suppose. I dislike the lowercase function names, and example's functional drive to cram the most function into the least amount of space. x -> x*x is nice and direct, but more complex things quickly get out of hand. I was a perl nut for about a year, but executable line noise is not the way to go...

And re-pasted from the thread for posterity, F# part 1: Print Lines of Code in a MSVS solution (minus exception handling).


open System.IO;

let IsSourceLine (Line:System.String) = Line.Trim().StartsWith(")

let GetLineCount FileName =

let GetSourceFileFromCompileLine Line=
let words = String.split ['\"'] Line
List.nth words 1

let ProjectLines ProjectPath =
let BaseDirectory = Directory.GetParent(ProjectPath).ToString()
let ProjectFileLines = List.of_array (File.ReadAllLines(ProjectPath))
let CompileLines = ProjectFileLines.Filter IsSourceLine
let SourceFiles = CompileLines.Map GetSourceFileFromCompileLine
let SourcePaths = SourceFiles.Map (fun x -> BaseDirectory + "\\" + x)
SourcePaths.Iterate (fun x -> System.Console.WriteLine(x))
let SourceFileLineCount = SourcePaths.Map GetLineCount
List.fold_left (+) 0 SourceFileLineCount

let IsProjectLine (Line:System.String) = Line.StartsWith("Project")

let GetProjectPath Line =
let words = String.split [','] Line
let second = List.nth words 1
let second = second.Replace("\"","")

let LinesPerSolutionFile SolutionFile =
let BaseDirectory = Directory.GetParent(SolutionFile).ToString()
let Lines = List.of_array (File.ReadAllLines(SolutionFile))
let Lines = Lines.Filter IsProjectLine
let ProjectFiles = Lines.Map GetProjectPath
let ProjectPaths = ProjectFiles.Map (fun x -> BaseDirectory + "\\" + x)
//ProjectPaths.Iterate (fun x -> System.Console.WriteLine(x))
let ProjectLineCounts = ProjectPaths.Map ProjectLines
List.fold_left (+) 0 ProjectLineCounts

let Main =
//let args = Set.of_array (System.Environment.GetCommandLineArgs())
let args = [@"C:\src\Csharp-moeClient2\Csharp-moeClient2.sln"]
let LineCounts = args.Map LinesPerSolutionFile
(List.combine args LineCounts).Iterate (fun (path, lineCount) -> System.Console.WriteLine("{0}: {1}",path,lineCount))

//do System.Console.WriteLine("Foo.");
//do Main

do System.Threading.Thread.Sleep(5000)

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!