Designing an F# module to be called by C# (Console/MVC/WPF) -
i have been trying use deedle f# library write f# batch program. has worked perfectly. however, not sure best design following 2 tasks:
combine f# module existing asp.net mvc/web api system
create wpf interface serve control panel , visual dependency controller various f# modules.
the type of tasks f# modules doing processing time series , applying statistical processes derive new time series.
i have been trying create class wrapper existing module can called c# code. read c# deep dive better way expose f# modules c# callers.
the following sample wrapper:
type timeseriesdataprocessor(filename:string) = let mutable _filename = filename let _rawinputdata = loadcsvfile _filename let _pivoteddata = _rawinputdata |> pivotrawdata |> fillpivotedrawdata |> calculateexpandingzscore //read , write member this.filename () = _filename , set (value) = _filename <- value member this.rawinputdata () = _rawinputdata member this.pivoteddata () = _pivoteddata member this.rawinputdatacount () = _rawinputdata.rowcount member this.pivoteddatacount () = _pivoteddata.rowcount
the following sample module of logic should reside:
module common = let loadcsvfile (filename:string ) : frame<int,string> = let inputdata = frame.readcsv(filename) inputdata let pivotrawdata inputdata:frame<datetime,string> = let pivoteddata = inputdata |> frame.pivottable (fun k r -> r.getas<datetime>("date")) (fun k r -> r.getas<string>("indicator")) (fun f -> let maxval = f?value |> stats.max match maxval | mv -> mv | _ -> double.nan ) pivoteddata let fillpivotedrawdata inputdata:frame<datetime,string> = let filleda = inputdata?a |> series.fillmissing direction.forward inputdata?a<-filleda let filledb = inputdata?b |> series.fillmissing direction.forward inputdata?b<-filledb inputdata let calculateexpandingzscore inputdata:frame<datetime,string> = let expandingmeancola = inputdata?a |> stats.expandingmean let expandingmeancolb = inputdata?b |> stats.expandingmean let expandingstdevcola = inputdata?a |> stats.expandingstddev let expandingstdevcolb = inputdata?b |> stats.expandingstddev let expandingzscorecola = (inputdata?a - expandingmeancola)/expandingstdevcola let expandingzscorecolb = (inputdata?b - expandingmeancolb)/expandingstdevcolb inputdata?expdingmeana <- expandingmeancola inputdata?expdingmeanb <- expandingmeancolb inputdata?expdingstdeva <- expandingstdevcola inputdata?expdingstdevb <- expandingstdevcolb inputdata?expdingzscorea <- expandingzscorecola inputdata?expdingzscoreb <- expandingzscorecolb inputdata
i have been trying use nunit serve c# caller. found myself putting of logic in class do/let binding
. member methods serving passing results caller. don't think approach correct.
can point me right direction? (i attempted learn f# wpf framework on github, not yet task)
i aware deedle avalable c#. but, want use f#. sample code has many side effects.
to put bluntly, want build little of ui , framework in f# possible. have noted, f# great language when it's great; otherwise, not recommended application building (some hardcore functional-language-fanboys might fight me on that, stand it, haha).
i recommend putting of unit-of-work f# code in portable f# library (https://msdn.microsoft.com/en-us/library/hh913781.aspx). then, referencing library , calling methods simple calling classes , methods c# or vb classes , methods.
there templates can use (http://blogs.msdn.com/b/mcsuksoldev/archive/2011/06/05/f-class-library-template.aspx).
Comments
Post a Comment