Hi guys,

 

I need some help with F# I'm trying to convert the below C# into F#

I have one function in SSSSLib.cs

 

        public double lagrangeInterpolatingPolynomial(List<ShareEntity>
share, int degree, int desiredPos)

        {

            double retVal = 0;

 

            for (int i = 0; i < degree; ++i)

            {

                double weight = 1;

 

                for (int j = 0; j < degree; ++j)

                {

                    // The i-th term has to be skipped

                    if (j != i)

                    {

                        weight *= (double)(desiredPos - share[j].Key) /
(share[i].Key - share[j].Key);

                    }

                }

 

                retVal += weight * share[i].Value;

            }

 

            return retVal;

        }

 

In another file ShareEntity.cs I have the below

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ShamirSecretSharingLibrary

{

    public class ShareEntity

    {   

        public long Key { get; set; }

        public long Value { get; set; }

    }

}

 

 

 

 

 

My new F# example in SSSSLib.fs I have 

module SSSSLib

 

let lagrangeInterpolatingPolynomial(share : List<ShareEntity>, degree,
desiredPos) = 

    let retVal = 0

    for i in 0 .. degree do

        let weight : double = 1.0

        for j in 0 .. degree do 

            if i <> j then

                printfn "i not = j"

                weight *= (desiredPos - share[j].Key) / (share[i].Key -
share[j].Key)

            else 

                None

 

In ShareEntity.fs I have

 

module ShareEntity

 

type ShareEntity =     

    member this.Key with get () = ()

    member this.Key with set () = ()

 

    member this.Value with get () = ()

    member this.Value with set () = ()

 

 

At the moment the compiler is complaining that on the line

let lagrangeInterpolatingPolynomial(share : List<ShareEntity>, degree,
desiredPos) = 

in SSSSLib.fs it isn't able to find ShareEntity. 

 

Anyone have any ideas?

 

Thank you in advance,

Tom

 

 

 

Reply via email to