f#

How to turn byte array into an image?

…衆ロ難τιáo~ 提交于 2020-01-06 08:20:08
问题 I have an 3D byte[,,] array(i, x, y), inside it it has i = B/G/R and x = x coordinates and y = y coordinates . eg. i = 2 x = 100 y = 200, red component of pixel(100,200) or i = 0 x = 100 y = 200, blue component of pixel(100,200) Yes I know RGB is in reverse order. Now, I'm not sure how to turn this byte[,,] into an image. I've looked at http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx. If I use SetPixel(), will it be really slow? How can I avoid using SetPixel()? I'm trying

WebSharper: Rpc-returned object are unusuable on the client or cause error

爱⌒轻易说出口 提交于 2020-01-06 07:53:10
问题 I have a few server-side objects with inheritrence hierarchy, like this: [<JavaScriptExport>] type [<AbstractClass>] A() = ... [<JavaScriptExport>] type [<AbstractClass>] B() = inherit A() [<JavaScriptExport>] type C() = inherit B() The above objects have certain fields and methods, which I have omitted for brevity. All of those can be compiled to javascript -- I receive no build errors. I have an RPC that would return a server-side created instance of such an object: module Remoting = [<Rpc>

How to keep recording key strokes while program not in focus (in background) in F#?

独自空忆成欢 提交于 2020-01-06 07:10:34
问题 The code below is part of a bigger ML project, but I want it to run while it's minimised too. How can I do this? I think I need to run it as a windows process to achieve this, but there isn't much information on how to do that in F#. Or is there another way? let rec f() = let c = System.Console.ReadKey().KeyChar printfn "%c" c f() f() 回答1: From the link in Aaron's comment I decided to give the port a try. This works for me. Note that this could definitely be cleaned up a bit more. I placed

summing elements from a user defined datatype

旧巷老猫 提交于 2020-01-06 05:00:27
问题 Upon covering the predefined datatypes in f# (i.e lists) and how to sum elements of a list or a sequence, I'm trying to learn how I can work with user defined datatypes. Say I create a data type, call it list1: type list1 = A | B of int * list1 Where: A stands for an empty list B builds a new list by adding an int in front of another list so 1,2,3,4, will be represented with the list1 value: B(1, B(2, B(3, B(4, A)))) From the wikibook I learned that with a list I can sum the elements by doing

summing elements from a user defined datatype

馋奶兔 提交于 2020-01-06 05:00:05
问题 Upon covering the predefined datatypes in f# (i.e lists) and how to sum elements of a list or a sequence, I'm trying to learn how I can work with user defined datatypes. Say I create a data type, call it list1: type list1 = A | B of int * list1 Where: A stands for an empty list B builds a new list by adding an int in front of another list so 1,2,3,4, will be represented with the list1 value: B(1, B(2, B(3, B(4, A)))) From the wikibook I learned that with a list I can sum the elements by doing

Convert C# code to F# code: lists manipulation

两盒软妹~` 提交于 2020-01-06 04:52:04
问题 Good morning at all, first I present myself: my name is Mattia and I'm a student in Computer Science. I've a problem with three function that I've already implement in two other programming language (C# and Python), using imperative loop like for and while, but what I've to do is to convert them in the recursive style. The function in C# are: resetList: given two list, the method initialize the counters inside the object of first list, and put the new object in the second list. public static

F# Filtering multiple years

老子叫甜甜 提交于 2020-01-06 03:06:26
问题 My objective is to find the total amount of sun for the following years - 1960,1970,1980,1990,2000,2010. The data comes from a txt file and year, month, maxt, mint, afday, rain and sun have already been defined and take the relevant element from the tuple, then it ignores the rest. // Example let sun (_,_,_,_,_,_,t) = t I have found the total amount of sun for the year 1960. However, I am not sure how to find the remaining years. let Q6 = ds |> List.filter (fun s-> year(s)=1960) |> List.sumBy

How to traverse String[][] in F#

北慕城南 提交于 2020-01-06 02:47:08
问题 Context: Microsoft Visual Studio 2015 Community; F# I've been learning F# for about 1/2 a day. I do have a vague idea of how to do functional programming from a year spent fiddling with mLite. The following script traverses a folder tree and pulls in log files. The files have entries delimited by ~ and there may be one or more there. open System open System.IO let files = System.IO.Directory.GetFiles("C:\\scratch\\snapshots\\", "*.log", SearchOption.AllDirectories) let readFile (file: string)

F# Using List.map on an array of strings

走远了吗. 提交于 2020-01-06 01:28:20
问题 I'm trying to use F#'s List.map function to call a function I've written on every string in the array. Here is the function I've written (*Takes a string and filters it down to common text characters*) let filterWord wordToFilter = Regex.Replace(wordToFilter, "[^a-zA-Z0-9/!\'?.-]", ""); and here is my main method where I call it (*Main method of the program*) [<EntryPoint>] let main argsv = let input = File.ReadAllText("Alice in Wonderland.txt"); //Reads all the text into a single string let

Changing dependency of WebSharper.JQueryUI to load jquery-ui.js locally

落花浮王杯 提交于 2020-01-05 21:14:27
问题 I'm writing on a WebSharper sitelet that uses the JQueryUI extension. The HTML generated by the WebSharper sitelet looks like this: <html> <head> ... <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js" ...></script> I'm frequently without internet while developing, so I'd really like to serve jquery-ui.js off the development server instead. That is, I'd much rather have this: <html> <head> ... <script src="/Scripts/jquery-ui.js" ...></script> The docs say this should be possible by setting