c# to f# - Using IRepository interfaces in f# -


i'm rewriting graduate student project written in c# f#.

i'm stumped on how handle irepository interfaces in f#. seems trivial in c#, f# doesn't i've done.

the irepository in question defined in mynamespace.solarsystem name space. make sure include in f# project.

here notes:

f# - invalid use of interface type <--(let repo = irepository<solarsystem>())

open mynamespace.solarsystem  let searchcatalog = [| 8; 11; 31 |]  let repo = irepository<solarsystem>()  let classofsolarsystems classofstar =      repo.query().where(fun s -> s.solargroups.any(fun c -> searchcatalog.contains(classofstar) )) 

c# - no error:

using mynamespace.solarsystem  private readonly int[]  searchcatalog = new int[] { 8, 11, 31 };  public irepository<solarsystem> repo { get; set; }  public ienumerable<solarsystem> classofsolarsystems(int32 classofstar) {     return repo.query()     .where(s => s.solargroups.any(c =>   searchcatalog.contains(classofstar))); } 

i exhausted googlefu , not find meaningful(to me @ least) solutions.

is there way use irepository interfaces in f#?

thanks!

your f# line equivalent c#, keyword new implicit in f#.

var repo = new irepository<solarsystem>() 

the c# compiler not let either. also, c# example property, while in f# value binding. to define properties in f# need use member keyword.

edit

i played around editor bit until found compiler mildly happy about, came this.

let classofsolarsystems (repo : irepository<solarsystem>) classofstar =      repo.query()     |> seq.filter(fun s -> s.solargroups.any(fun c -> searchcatalog.contains(classofstar) )) 

i didn't mess linq expressions should consider using f# seq module instead.


Comments