f#-interactive

Find maximum, minimum and average in F#

浪子不回头ぞ 提交于 2019-12-06 03:15:05
问题 I want to find maximum, minimum and average in an array without .NET in F#. I used this code but it is not working: let mutable max = 0 let arrX = [|9; 11; 3; 4; 5; 6; 7; 8|] for i in 0 .. arrX.Length - 2 do if (arrX.[i]) < (arrX.[i+1]) then max <- arrX.[i] printfn "%i" max 回答1: I fixed your code for max let mutable max = 0 let arrX= [|9; 11; 3; 4; 5; 6; 7; 8|] for i in 0 .. arrX.Length - 1 do if max < (arrX.[i]) then max <- arrX.[i] printfn "%i" max To find max, min and avg, using your

in F# on MAC OSX and Ubuntu I get an error running FSI in 4.0

混江龙づ霸主 提交于 2019-12-06 03:08:24
I need System.Numerics in F# EDIT I think the question is can fsi run with the 4.0 runtime and if so how do I configure it I run "mono /bin/Fsi" in the Fsharp 4.0 dir I get the following error in both OSX 10.6.4 and Ubuntu 10.1. I am sure I am missing a path or something Please note the paths are different on the MAC but I got the same error error FS0078: Unable to find the file 'System.Numerics.dll' in any of /opt/mono-2.8/lib/mono/2.0 /home/gary/Downloads/FSharp-2.0.0.0/v4.0/bin /home/gary/Downloads/FSharp-2.0.0.0/v4.0/bin/ On my MAcbook I copied the mono 4.0 bin dir to one of the above

How to change F# Interactive newline character

ε祈祈猫儿з 提交于 2019-12-05 22:36:14
In a .fs file a newline is denoted by \r\n , but in the F# Interactive window it is \n . In a problem I'm currently trying to solve, the length of a multiple line literal string matters. So a problem arises when I am testing code in the F# Interactive window, because the length of the string is different from in normal execution. I hope there is an option to change the newline 'character' in F# Interactive to \r\n , but I can't find it. Does anyone know where I can achieve this, or some other workaround? You can use conditional compilation to handle this: #if INTERACTIVE text.Replace("\n",

Why does F# Interactive behave differently than compiler with regards to immutable value definition?

老子叫甜甜 提交于 2019-12-05 09:45:37
In reading John Palmer's answer to What is the difference between mutable values and immutable value redefinition? , John notes that This sort of redefinition will only work in fsi. In working with F# Interactive (fsi) I guess I subconsciously knew it, but never paid attention to it. Now that it is apparent, why the difference? More specifically please explain how the internals are different between fsi and the compiler such that this occurs by design or result of differences? If the answer can elaborate on the internal structures that hold the bindings that would be appreciated. The semantics

Find maximum, minimum and average in F#

送分小仙女□ 提交于 2019-12-04 08:26:26
I want to find maximum, minimum and average in an array without .NET in F#. I used this code but it is not working: let mutable max = 0 let arrX = [|9; 11; 3; 4; 5; 6; 7; 8|] for i in 0 .. arrX.Length - 2 do if (arrX.[i]) < (arrX.[i+1]) then max <- arrX.[i] printfn "%i" max I fixed your code for max let mutable max = 0 let arrX= [|9; 11; 3; 4; 5; 6; 7; 8|] for i in 0 .. arrX.Length - 1 do if max < (arrX.[i]) then max <- arrX.[i] printfn "%i" max To find max, min and avg, using your approach: let mutable max = System.Int32.MinValue let mutable min = System.Int32.MaxValue let mutable sum = 0 let

how to add third party dll reference to F# project?

女生的网名这么多〃 提交于 2019-12-04 00:40:52
I'm adding a third party dll reference to my F# project. I added the dll in references and when I use this i.e highlight the code and do Alt+Ent, I get the error "The namespace or module 'AZROLESLib' not defined." Am I missing some thing. In short, you have to use #r "/path/to/AZROLESLib.dll" in order that F# Interactive recognizes and loads the dll file. Adding a dll reference helps Visual Studio to find correct libraries when compiling the project, but it has nothing to do with F# Interactive. Therefore, you have to use #r directive to point to AZROLESLib.dll . If VS has some troubles to

How does F# Interactive #I command know about project path?

狂风中的少年 提交于 2019-12-03 06:32:32
Here is the scenario: Open Visual Studio. This was done in VS2010 Pro. Open F# Interactive within Visual Studio Open project with fsx file Note: Project and fsx file are in E:\<directories>\fsharp-tapl\arith Send commands to F# Interactive from fsx file > System.Environment.CurrentDirectory;; val it : string = "C:\Users\Eric\AppData\Local\Temp" I was not expecting a Temp directory but it makes sense. > #r @"arith.exe" Examples.fsx(7,1): error FS0082: Could not resolve this reference. Could not locate the assembly "arith.exe". Check to make sure the assembly exists on disk. If this reference is

How does fsi.ShowDeclarationValues work?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 04:10:09
According to the MSDN documentaion: When set to false, disables the display of declaration values in the output of the interactive session. However, the following sample interactive session seems to contradict that summary. > let x = 42;; val x : int = 42 > fsi.ShowDeclarationValues <- false;; val it : unit = () > let y = 42;; val y : int I was not expecting the last line above. Have I misunderstood something? Can anyone confirm if this is a bug? Thanks. Daniel is correct - this disables just printing of the values and not the declarations themselves. One situation where this is useful is when

Type mismatch error. F# type inference fail?

北慕城南 提交于 2019-12-02 01:45:51
问题 I'm trying to write a method in F# that returns a new instance of a generic type based upon the type of a value passed into the method. In FSI: open System.Collections.Generic type AttributeIndex<'a>() = inherit SortedDictionary<'a, HashSet<int array>>() let getNewIndexForValue (value: obj) : AttributeIndex<_> = match value with | :? string -> new AttributeIndex<string>() | :? int -> new AttributeIndex<int>() | :? float -> new AttributeIndex<float>() | :? bool -> new AttributeIndex<bool>() |

Bitmap image manipulation

会有一股神秘感。 提交于 2019-12-01 20:20:42
I want to replace GetPixel and SetPixel using LockBits method, so I came across this F# lazy pixels reading open System.Drawing open System.Drawing.Imaging let pixels (image:Bitmap) = let Width = image.Width let Height = image.Height let rect = new Rectangle(0,0,Width,Height) // Lock the image for access let data = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat) // Copy the data let ptr = data.Scan0 let stride = data.Stride let bytes = stride * data.Height let values : byte[] = Array.zeroCreate bytes System.Runtime.InteropServices.Marshal.Copy(ptr,values,0,bytes) // Unlock the