f#

Get pixel length from PixelFormat

和自甴很熟 提交于 2019-12-23 12:06:59
问题 How can i get pixel length (in bytes) from PixelFormat enumeration? I want to process image pixels using native approach, but how can i iterate through an image if i don't know pixel's offset. Code: let formRgbCube (image : Bitmap) = let width = image.Width let height = image.Height let bitmapData = image.LockBits(Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat) let ptr = NativePtr.ofNativeInt<byte>(bitmapData.Scan0) let stride = bitmapData.Stride let

How to take F# measurements to get speedups

非 Y 不嫁゛ 提交于 2019-12-23 11:51:22
问题 Assuming a single machine with 8 cores. In Haskell, you can compile using the threaded option, then during runtime use +RTS -Nx to specify the number of cores to be used. e.g. $ myprg args // sequential run $ myprg args +RTS -N1 // parallel run on 1..8 cores $ myprg args +RTS -N2 $ myprg args +RTS -N4 $ myprg args +RTS -N8 From this, you get the runtimes using increasing number of cores, which you can then use to get speedups and plot a graph. How would you do this in F#, assuming I have a

Haskell to F# - declare a recursive types in f#

一个人想着一个人 提交于 2019-12-23 11:44:15
问题 I am trying to teach my self F# by porting some Haskell Code. Specifily I am trying to port the Countdown Problem shown here The Haskell Code is listed here I am trying to create the following Haskell types in F#: data Op = Add | Sub | Mul | Div data Expr = Val Int | App Op Expr Expr In F# I think Op type is defined as follows: type Op = | Add | Sub | Mul | Div I am having issues with the Expr type. How does one create a recursive type? From this SO question it looks like one can not create

What do “the mustinline value … was not inferred to have a known value” and “marked inline but not bound in the optimization environment” mean?

六月ゝ 毕业季﹏ 提交于 2019-12-23 11:36:17
问题 I have run into a compile-time error I do not understand while working with F# in Visual Studio 2012. I could find a minimal snippet here: http://ideone.com/hbhbF type Foo() = inherit System.Exception() member inline this.Bar() = () Foo().Bar() What do the following error messages mean? /home/iU0RLi/prog.fs(3,22): error FS0073: internal error: the mustinline value 'Bar' was not inferred to have a known value /home/iU0RLi/prog.fs(5,1): error FS1114: The value 'Prog.Foo.Bar' was marked inline

F# passing none to function, getting null as parameter value

怎甘沉沦 提交于 2019-12-23 10:57:33
问题 This is really weird and I fear I have just done something dumb but I can't figure it out. I'm passing None to the function some as the first parameter but when the function executes, the value of parentNode is null (I'm not concerned with it printing null for None , the function parameter value IS null not None ). I end up getting a null reference error on the print function line because parentNode is null. I've tried to tuple the args and change the order but that didn't help. I have a

Am I using TextLoader wrong when running the ML.Net Iris demo in F#?

此生再无相见时 提交于 2019-12-23 10:57:15
问题 I am new to F#/.NET and I am trying to run the F# example provided in the accepted answer of How to translate the intro ML.Net demo to F#? with the ML.NET library, using F# on Visual Studio, using Microsoft.ML (0.2.0). When building it I get the error error FS0039: The type 'TextLoader' is not defined. To avoid this, I added the line open Microsoft.ML.Data to the source. Then, however, the line pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ",")) triggers: error FS0033: The non

Hosting .fsx scripts inside larger applications

筅森魡賤 提交于 2019-12-23 10:49:34
问题 I want to expose my F# libraries as a scriptable tool for data manipulation. Optimally, I want this scripting facility to not require a full F# install with fsi and so on. Is there a way to link into the FSI libraries to execute scripts from F# code? My google-fu is failing me on this one, and the F# sources for fsi are a bit tangled. 回答1: No, there's no hosting API for F# interactive sessions. fsi.exe itself is factored into a lightweight client process that handles the interaction, and a

Why are flexible types not allowed in record type definitions?

北战南征 提交于 2019-12-23 10:49:18
问题 I'm trying this: type TS1<'state, 'action> = { actions : 'state -> #seq<'action> move : 'state -> 'action -> 'state state0 : 'state } But the type checker won't let me: .../stdin(2,29):error FS0715: Anonymous type variables are not permitted in this declaration However, if I unfold the definition of the flexible type, I'm good: type TS2<'state, 'action, 'actions when 'actions :> seq<'action>> = { actions : 'state -> 'actions move : 'state -> 'action -> 'state state0 : 'state } I'm unhappy

Use of typeof<_> in active pattern

时光怂恿深爱的人放手 提交于 2019-12-23 10:34:07
问题 Given the following contrived active pattern: let (|TypeDef|_|) (typeDef:Type) (value:obj) = if obj.ReferenceEquals(value, null) then None else let typ = value.GetType() if typ.IsGenericType && typ.GetGenericTypeDefinition() = typeDef then Some(typ.GetGenericArguments()) else None The following: let dict = System.Collections.Generic.Dictionary<string,obj>() match dict with | TypeDef typedefof<Dictionary<_,_>> typeArgs -> printfn "%A" typeArgs | _ -> () gives the error: Unexpected type

Reusing type definitions with JSONProvider?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 10:26:58
问题 I'm using the JSONProvider from FSharp-Data to automatically create types for a webservice that I'm consuming using sample responses from the service. However I'm a bit confused when it comes to types that are reused in the service, like for example there is one api method that return a single item of type X while another returns a list of X and so on. Do I really have to generate multiple definitions for this, and won't that mean that I will have duplicate types for the same thing? So, I