You need to wrap the object construction within parens:

1
let dir = (new DirectoryInfo(root)).GetDirectories().TakeWhile(dir => readRequest.Providers.Contains(dir.Name))
By on 1/7/2009 5:22 AM ()

Hi,

The new is superfluous here (only required with types implementing IDisposable,) and removing it allows you to dot straight into

1
GetDirectories()

.

You'll also need to replace the C# lambda syntax with F#'s fun:

1
2
3
4
5
6
7
8
#r "System.Core.dll"


open System.IO
open System.Linq


let dir = DirectoryInfo("c:/").GetDirectories().TakeWhile(fun (dir :DirectoryInfo)-> dir.Name.Length > 10)

I found that type inference failed on the lambda in

1
TakeWhile()

so I had to explicitly annotate with

1
DirectoryInfo

. Did anyone else experience this?

Having a strongly-binding #light-aware operator keyword => could possibly be a nice addition to the language as it would reduce the number of parentheses that the fun keyword tends to require.

regards,

Danny

By on 1/7/2009 5:40 AM ()

I found that type inference failed on the lambda in

1
TakeWhile()

so I had to explicitly annotate with

1
DirectoryInfo

. Did anyone else experience this?

Yes.

1
2
3
4
5
6
> let dir2 = DirectoryInfo("c:/").GetDirectories().TakeWhile(fun (dir)-> dir.Name.Length > 10);;

  let dir2 = DirectoryInfo("c:/").GetDirectories().TakeWhile(fun (dir)-> dir.Name.Length > 10);;
  -----------------------------------------------------------------------^^^^^^^^^^^^^^^^

stdin(12,72): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved

Is F# type inference going to end up being as ill-defined as the VB6 grammar? [6]

By on 1/7/2009 6:16 AM ()

Use

1
let dir2 = DirectoryInfo("c:/").GetDirectories() |> Seq.take_while(fun dir -> dir.Name.Length > 10)
By on 1/7/2009 9:06 PM ()

Good suggestion in the case of Linq to Objects (my simple example above), but it would not produce the required results when using Linq to Sql or most other Linq providers.

By on 1/8/2009 3:44 AM ()

Hmm... this is possibly a bug with type inference and C# extension methods. Someone from the F# team should confirm this though. I don't think you'd need a type annotation if TakeWhile was a regular method.

By on 1/8/2009 3:20 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper