F# Tip of the Week (26 August 2013)

It’s possible to use function composition and modify the type of value returned.  Consider the following equation:

1/4x2

I might encode the function to calculate this like so:


let square x = x * x

//Want this to be a float because if this is an int division

// it will always round to 0 if x is greater than 1.

let recip x = 1.0/x

let myFunc =  fun x -> 4* (square x) >> recip

This function composition will not work because I need to pass a float to recip. But I can make it work by doing this:


let square x = x * x

let recip x = 1.0/x

let myFunc = fun x -> 4* (square x) >> float >> recip

 

There’s a great deal more information on conversion functions in F# here.

First Detroit F# Meetup

A few of us from Quicken had attended LambdaJam in Chicago.  By the way, it was a great conference–big kudos to Alex Miller. Anyway, at that conference we met Mathias Brandewinder, a Microsoft F# MVP from San Francisco.  Some of the guys started talking to Mathias about visiting us here in Motown to spread the F# goodness.

One thing lead to another and we were able to get him to come here.  John Fair, myself, and a few others interested in F# were talking about what we could do to make his visit most effective for teaching folks around here about F#.  I had been running an F# user group here till around 2011 or so.  I’ve run a few user groups in my time and I can tell you that they often end up being a major chore and by 2011 I was just kind of tired of being in charge of things.  But this time John and the others volunteered to lead the effort so it was hard to argue with.

At any rate, Mathias lead a machine learning coding dojo and it just blew us all away–how much fun it was.  To tell you the truth I was sort of skeptical–I mean how much can one learn about machine learning and its algorithms and techniques in one short session.  But there was a lot there and we had a great time.

Kudos to Mathias for leading an awesome session and to John and those other F# folks who got him to join us and set up the session.

Here are some pics I took at the meetup:

 

Some of the fellows at the first F# meetup

Some of the fellows at the first F# meetup

Some of the fellows standing around chatting

Some of the fellows standing around chatting

F# Tip Of The Week (Week of August 19, 2013)

Even though tuples, records and discriminated unions are reference types, they all have the built-in equality properties you would expect in a value type.  For example:


> let a = (1,'a');;

val a : int * char = (1, 'a')

> let b = (1,'a');;

val b : int * char = (1, 'a')

> a = b;;

val it : bool = true

That is, you get the equality behavior you would expect rather than the usual equality behavior associated with reference types.  Here’s an example of records and the built-in equality checking:


> type rec1 = {

a:int

b:string

};;

type rec1 =

{a: int;

b: string;}

> let a = {a=1;b="one"};;

val a : rec1 = {a = 1;

b = "one";}

> let b = {a=1;b="one"};;

val b : rec1 = {a = 1;

b = "one";}

> a = b;;

val it : bool = true

A Brief Thought On Conference “Swag”

Were I sponsoring a technology conference, I’d much rather get my logo on a coffee mug than just about anything else from the conference.  Why do I say this?  Consider some other alternatives: a t-shirt, a thumb drive, a pen.  

No matter how slovenly a developer, he or she will only wear a t-shirt once every couple of weeks.  A pen sits on a developer’s desk unused most of the time.  Now other developers may use thumb drives much more than I do but I rarely find myself using a thumb drive.

The one thing I do as a developer is get myself coffee–every day.  Day in, day out.  T-shirts wear out, pens get used up, thumb drives get lost, but I still have coffee mugs I’ve had for literally ten years.  Of course coffee mugs get broken too but in the meantime I do believe developers will see your logo and get the brand awareness much more with a coffee cup than with any other swag you can brand for a conference.  Just sayin’.

 

 

F# Tip Of The Week (Week of August 12, 2013)

The F# developer can use pattern matching syntax pretty much anywhere in F#.  For example, consider the following list:


let l = [1..25]

If I want to get the last element of the list, I can do this with a little trivial pattern match:


let lastElem::_ = l |> List.rev;;

stdin(7,5): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[]' may indicate a case not covered by the pattern(s).

val lastElem : int = 25

In this case, you can safely ignore the warning.

You can also pull one of the elements from a tuple very easily with this pattern match:


let name,_ = (“Onorio”,”11W”);;

val name : string = "Onorio"

The underscore character in both of these pattern matches functions as a wildcard.  In both cases it signifies a value that we don’t care about.

Getting The Band Back Together

So back in 2011 I was trying to get an F# user group going here in Detroit.  As is so often the case with user groups, most of the responsibility for setting things up and arranging things was falling on one person–me.  In fairness, the folks at Epitec did their best to help; they provided us a place to meet and they provided food.  Still I was the one always doing the presentations and, as anyone who’s ever run a user group knows, that burns a person out in short order.

Still I really wanted people to know the F# story; I think it’s very compelling.  Fast forward to 2012 when I joined John Fair at Quicken Loans.  John is another F#anatic (to coin an unnecessary neologism). John and I have both been running a weekly F# learning session for quite some time.  So yesterday I felt it’s time to apply some of what I’ve learned since 2011 and give another try to running an F# user group here in Detroit.  John has graciously agreed to help and I know that means I won’t be stuck doing all the heavy lifting.

We’re meeting on August 22; location is still to be determined as is the topic of the first meeting.  But either way, I am excited to once again be able to start sharing the F# goodness.  And there is a lot of goodness there.

http://www.meetup.com/Detroit-F-Meetup/