Live data from Hacker News

.NET Fiddle adds F#

dotnetfiddle.net

31–40 of 72 posts

Re: .NET Fiddle adds F#

#31

Cool to "see" F# in action. Like the union types, but not so much the list operations; seems more natural to: [1;2;3;4] filter isEven sum vs. List.filter isEven [1;2;3;4] |> List.sum in Scala it's: List(1,2,3,4) filter isEven sum Of course I'm not familiar with F# so don't know all of the WIN within (Type Providers, for example, are very impressive, would love to see that on the Scala side of the fence one day).

I've got little experience with Scala, but judging from your sample it looks like what's happening is that Scala follows more Java-y idioms for how code is structured.

So in

  List(1,2,3,4) filter isEven sum
it looks like filter and sum are instance methods on the List class, and I'm guessing isEven is a predicate that's being passed as an argument to the filter method.

F# leans closer to its functional roots in this respect, so it's more idiomatic to keep object-oriented constructs at arm's reach in most your code. The language has full support for OOP, it's just that you're not expected to trot it out except when you're writing public interfaces that are meant to be consumed by code that might be written in C# or VB.NET. So the List class mostly sticks to static methods in its public interface because that approach fits better with traditional functional idioms.

That gets you as far as something like this:

  List.sum (List.filter isEven [1;2;3;4])
The next step is the "pipeline" operator, which is defined as

  let inline (|>) x f = f x
So it's just letting you swap a function and its argument, which facilitates reorganizing the code so that the functions are listed in the order in which they execute. That's what gets you to the example you give - or better yet:

  [1;2;3;4]
  |> List.filter isEven
  |> List.sum
which I think captures some of the natural expression that you were talking about while still sticking with functional idioms instead of object-oriented ones.

Re: .NET Fiddle adds F#

#32
post #28

Anybody managed to install F# on Ubuntu? There are recommended steps [0] but they've never worked for me even on a new 13.04 (& later) image on DigitalOcean. [0] http://fsharp.org/use/linux/

I use F# on Windows and FreeBSD, but I've used it on Ubuntu a few times before for testing. Here's how I did installed it:

  git clone git://github.com/mono/mono.git
  cd mono
  autogen.sh
  sudo make install clean
  cd ..
  git clone git://github.com/fsharp/fsharp.git
  cd fsharp
  autogen.sh
  sudo make install clean
It takes a while to build Mono from scratch, but this way has always worked for me.

Re: .NET Fiddle adds F#

#33
post #30

Earlier quoted context omitted.

I've done very little but it seems really concise. I like that. One place some predict it will emerge is in the Web API arena, and I could totally see that happening.

Why? What makes it better than C# in web Web API area? (honest question)

Type providers for one: http://msdn.microsoft.com/en-us/library/hh156509.aspx

http://channel9.msdn.com/posts/Tomas-Petricek-How-F-Learned-...

Re: .NET Fiddle adds F#

#34
post #29

Earlier quoted context omitted.

That seems odd. It seems that `arg |> func` would simply be sugar for `func arg` (or a function that accomplished this). Why are they not equivalent?

F# type inference runs left -> right, top -> bottom. In the first snippet, the lambda is encountered first, and the compiler has no knowledge of what the type of "d" is, so it can't assume d has a ".Hour" member. In the second snippet, the compiler has already seen the input list and knows it contains DateTimes, so when it encounters the lambda, "d" is known to be a DateTime and everything is groovy.

Ah, I see, thanks for that. So it's not running Hindley Milner (or at least, not unless it's quite heavily modified). That's not surprising, I guess, since it takes no small amount of effort to get HM to work in an OO/imperative setting.

Re: .NET Fiddle adds F#

#35
post #28

Anybody managed to install F# on Ubuntu? There are recommended steps [0] but they've never worked for me even on a new 13.04 (& later) image on DigitalOcean. [0] http://fsharp.org/use/linux/

I use F# on Windows and FreeBSD, but I've used it on Ubuntu a few times before for testing. Here's how I did installed it: git clone git://github.com/mono/mono.git cd mono autogen.sh sudo make install clean cd .. git clone git://github.com/fsharp/fsharp.git cd fsharp autogen.sh sudo make install clean It takes a while to build Mono from scratch, but this way has always worked for me.

Your steps are almost the same as the one I linked. But I tried them, just in case. And it still does not build. The fsharp build fails with some error about casting types. Do you have version details?

Re: .NET Fiddle adds F#

#36
post #33
post #30

Earlier quoted context omitted.

Why? What makes it better than C# in web Web API area? (honest question)

Type providers for one: http://msdn.microsoft.com/en-us/library/hh156509.aspx http://channel9.msdn.com/posts/Tomas-Petricek-How-F-Learned-...

Anything specific on F# applied to Web API?

Re: .NET Fiddle adds F#

#37

Cool to "see" F# in action. Like the union types, but not so much the list operations; seems more natural to: [1;2;3;4] filter isEven sum vs. List.filter isEven [1;2;3;4] |> List.sum in Scala it's: List(1,2,3,4) filter isEven sum Of course I'm not familiar with F# so don't know all of the WIN within (Type Providers, for example, are very impressive, would love to see that on the Scala side of the fence one day).

In F#, most pipelined operations are expressed using the pipeline operator all the way. [1; 2; 3; 4] |> List.filter isEven |> List.sum That way you maintain the same operator order as you do in Scala, while maintaining some consistency with currying. In addition, you can add other functions really simply while still maintaining the order. [1; 2; 3; 4] |> List.filter isEven |> List.sum |> printfn "%i"

Interesting, in Scala you do:

list filter isEven foreach println

Which is, IMO, quite elegant, but then again I'm used to Scala and not yet at all familiar with F# and the reasoning behind the syntax.

Re: .NET Fiddle adds F#

#38
post #33

Earlier quoted context omitted.

Type providers for one: http://msdn.microsoft.com/en-us/library/hh156509.aspx http://channel9.msdn.com/posts/Tomas-Petricek-How-F-Learned-...

Anything specific on F# applied to Web API?

F# has asynchronous workflows, which is a nice API for task parallelism built on computation expressions, which are sort of tamed monads.

That edge dulled quite a bit with C# 5.0 and async/await, though.

Re: .NET Fiddle adds F#

#39
post #35

Earlier quoted context omitted.

I use F# on Windows and FreeBSD, but I've used it on Ubuntu a few times before for testing. Here's how I did installed it: git clone git://github.com/mono/mono.git cd mono autogen.sh sudo make install clean cd .. git clone git://github.com/fsharp/fsharp.git cd fsharp autogen.sh sudo make install clean It takes a while to build Mono from scratch, but this way has always worked for me.

Your steps are almost the same as the one I linked. But I tried them, just in case. And it still does not build. The fsharp build fails with some error about casting types. Do you have version details?

Try building the 'fsharp_30' branch instead. The master branch just switched over to F# 3.1, so its possible they haven't worked out all of the bugs for every possible system yet.

When I ran F# on Ubuntu before, it was on the x86 version of 12.04 LTS. I used whatever the latest version of Mono was; I don't remember specifically, but it was almost certainly one of the 3.2.x versions.

Would you mind posting the build output from your F# build that fails (e.g., to pastebin or Gist)? I can forward it along to the right people so it gets fixed. Or, post it as a Github issue: https://github.com/fsharp/fsharp/issues

Re: .NET Fiddle adds F#

#40

Cool to "see" F# in action. Like the union types, but not so much the list operations; seems more natural to: [1;2;3;4] filter isEven sum vs. List.filter isEven [1;2;3;4] |> List.sum in Scala it's: List(1,2,3,4) filter isEven sum Of course I'm not familiar with F# so don't know all of the WIN within (Type Providers, for example, are very impressive, would love to see that on the Scala side of the fence one day).

I guess it's all a matter of what you're used to, because coming from ML-family languages like F# and Haskell, the first thing you wrote doesn't really make any sense to me. In the ML family like F# is, you put the function (e.g. "filter isEven") before the argument ([1;2;3;4]).

Right, which is why ML languages are a bit baffling for me, the ordering seems totally off ;-)

Just getting started with Haskell and am having several, shall we say, WTF moments.

Post reply on HN