//List.item N nameOfList returns the element at that index //List.findIndex(fun e -> e = element) nameOfList returns index of element // let detect2 listOfTuples (threshold:int)= // List.map(fun x -> edge (first(x)) (second(x)) threshold) listOfTuples // let rec func (L:(int*int*int)list list) (lastIdx:int) (threshold:int)= // match L with // | [] -> [] // | head::tail -> (detect2 head lastIdx threshold)::(func tail lastIdx threshold) let first (a,_,_) = a let second (_,b,_) = b let third (_,_,c) = c let list1 = [ [(0,0,0); (14,15,14); (9,8,7); (36,80,0)]; [(12,12,12); (45,15,45); (38,38,37); (45,25,10)] [(14,15,14); (9,8,7); (44,46,44); (0,0,0)]; [(12,12,12); (38,38,37); (45,15,45); (18,255,10)]] let L = List.item 0 list1 let B = List.item 1 list1 let newL = List.zip L B let lastIdx = list1.Length - 1 // List.mapi(fun i x -> if (i < lastIdx) then (greaterThanThreshold x (List.item (i + 1) row) threshold) else x) row // List.mapi (fun i x -> if (i < lastIdx) List.zip (List.item(i) list1) (List.item(i + 1) list1)) let greaterThanThreshold (T1:int*int*int) (T2:int*int*int) (threshold: int) = let (fir1:float) = float(first(T1)) let (sec1:float) = float(second(T1)) let (thd1:float) = float(third(T1)) let (fir2:float) = float(first(T2)) let (sec2:float) = float(second(T2)) let (thd2:float) = float(third(T2)) let (xD:float) = (fir1 - fir2) * (fir1 - fir2) let (yD:float) = (sec1 - sec2) * (sec1-sec2) let (zD:float) = (thd1 - thd2) * (thd1 - thd2) let (radicand:float) = xD + yD + zD let (sqR:float) = sqrt radicand let resTuple = if (sqR > (float(threshold)) ) then (0,0,0) else (255,255,255) resTuple //where x is a pair of tuples. returns a list of edge-detected pixels let detectZip tupleOfTuples (threshold:int)= List.map(fun x -> greaterThanThreshold (fst(x)) (snd(x)) threshold) tupleOfTuples // List.item N nameOfList returns the element at that index // List.findIndex(fun e -> e = element) nameOfList returns index of element let rec func1 (L:(int*int*int)list list) (lastElement: (int*int*int) list) = match L with | [] -> [] | head::head2::tail when head <> lastElement -> (List.zip head head2)::(func1 (head2::tail) lastElement) | head::tail -> [] let lastElement = List.item (list1.Length - 1) list1 printfn "%A" (func1 list1 lastElement) let rec func2 L threshold = match L with | [] -> [] | head::tail -> (detectZip(head.Head))::(func2 tail threshold) printfn "%A" (func2 list1 40)
Write, Run & Share F#
code online using OneCompiler's F# online compiler for free. It's one of the robust, feature-rich online compilers for F#
language, running on the latest version 4.0. Getting started with the OneCompiler's F#
compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as F#
and start coding.
OneCompiler's F#
online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample F#
program which takes name as input and prints hello message with your name.
open System
let name = Console.ReadLine()
Console.Write("Hello 0.\n", name)
F#
F#
(F sharp) is a functional programming language which was developed by Microsoft in the year 2005. F#
is .net implementation of OCaml. It can be used in variety of applications like graphic designing, Telecommunications, AI, CPU design, compiler programming, web applications, games etc.,
Data type | Description | Size | Range |
---|---|---|---|
sbyte | 8-bit signed integer | 1 byte | -128 to 127 |
byte | 8-bit unsigned integer | 1 byte | 0 to 255 |
int16 | 16-bit signed integer | 2 bytes | -32768 to 32767 |
unit16 | 16-bit unsigned integer | 2 bytes | 0 to 65,535 |
int/int32 | 32-bit signed integer | 4 bytes | -2,147,483,648 to 2,147,483,647 |
uint32 | 32-bit unsigned integer | 4 bytes | 0 to 4,294,967,295 |
int64 | 64-bit signed integer | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
uint64 | 64-bit unsigned integer | 8 bytes | 0 to 18,446,744,073,709,551,615 |
bigint | arbitrary precision integer | At least 4 bytes | Integers |
Data type | Description | Size | Range |
---|---|---|---|
float32 | 32-bit signed floating point number | 4 bytes | ±1.5e-45 to ±3.4e38 |
float | 64-bit signed floating point number | 8 bytes | ±5.0e-324 to ±1.7e308 |
decimal | 128-bit signed floating point number | 16 bytes | ±1.0e-28 to ±7.9e28 |
Data type | Description | Size | Range |
---|---|---|---|
char | single character | 2 bytes | U+0000 to U+ffff |
string | Text | 20 + (2 * length of the string) bytes | 0 to up to 2 billion characters |
bool | Stores either true or false | 1 byte | True or false |
Variable is a name given to the storage area in order to manipulate them in our programs.
let variable_name:data-type = value
let mutable variable_name:data-type = value
When ever you want to perform a set of operations based on a condition or set of conditions then If or IF-ELSE or Nested If-Elif-Else are used.
if conditional-expression then
// code
if conditional-expression then
// code
else
// code
if conditional-expression then
// code
elif conditional-expression then
// code
elif conditional-expression then
// code
...
else
// code
For loop is used to iterate a set of statements based on a condition.
Iteration occurs in ascending order
for var = start-expression to end-expression do
// code
Iteration occurs in descending order.
for var = start-expression downto end-expression do
// code
This loops is used when iteration occurs over enumerable collection like arrays, lists, sequences, range expression etc.
for pattern in enumerable-collection-expr do
// code
let listItems = [1,2,3,4,5]
for x in listItems do
printfn "%d" x
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition-expr do
// code
In F#
, You can declare and use functions similar to Variables. In simpler words, you can understand them as user-defined variables.
let [inline] function-name parameter-list [ : return-type ]
= function-body
let VarName = function-name parameter-list