Create Multi-Parameter Pipeable Function F# -


i want generalize standard deviation function allow calculations of multiples of deviations, still use in context of piping. appears setting function incorrectly.

let variance (x:seq<float>) = let mean = x |> seq.average x |> seq.map(fun x -> (x - mean) ** 2.0)   |> seq.average  let stddeviation (deviations:float, x:seq<float>) =   sqrt (x |> variance) * deviations  

example usage be

let stester = seq{1.0 .. 20.0} let stddev = stester |> stddeviation 1.0  

i keep getting error: expression expecting have type: seq -> a' here has type float

help appreciated.

thanks,

~david

if change stddeviation takes 2 parameters, rather tuple works:

let stddeviation (deviations:float) (x:seq<float>) =   sqrt (x |> variance) * deviations   let stddev = stester |> stddeviation 1.0  

the idea when write let stddeviation (deviations, x:seq<float>) defining function takes single parameter tuple.

the way |> operator works supplies 1 parameter function on right. if have 1 parameter (which tuple), pipe isn't useful.

but if let stddeviation deviations (x:seq<float>) defining function 2 parameters. when write input |> stddeviations 1.0 providing first parameter on right hand side , input (second parameter) on left via pipe.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -