0 people like it.

Control Flow via Index Exceptions

Simple, but slow. Don't do this at home :)

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
open System

let digits = """
00000000000001111111110000000000
00000000001111111111111000000000
00000000011111111111111100000000
00000000011111111111111100000000
00000000011111111111111110000000
00000001111111111111111100000000
00000000111110000011111100000000
00000000000000000001111100000000
00000000000000000001111100000000
00000000000000000001111100000000
00000000000000000011111000000000
00000000000000000111111000000000
00000000000000000111111000000000
00000000000000000111111000000000
00000000000000001111110000000000
00000000011111111111111111000000
00000000111111111111111111100000
00000000111111111111111111100000
00000000111111111111111111100000
00000001111111111111111110000000
00000001111111111110000000000000
00000001111111111110000000000000
00000000111111111110000000000000
00000000000011111000000000000000
00000000000011111000000000000000
00000000000011111000000000000000
00000000000111111000000000000000
00000000000111111000000000000000
00000000001111110000000000000000
00000000011111110000000000000000
00000000001111100000000000000000
00000000001111100000000000000000
 7
00000000000000000001111100000000
00000000000000000011111100000000
00000000000000001111111100000000
00000000000001111111111100000000
00000000000011111111111110000000
00000000000011111111011111000000
00000000001111111100011111000000
00000000011111111000011111000000
00000000011111100000011111000000
00000000111111000000111110000000
00000001111110000000111110000000
00000011111110010001111111000000
00000111111111111111111111000000
00000111111111111111111111100000
00000111111111111111111111000000
00000011111111111111111111100000
00000001111111111111111111000000
00000000000000000111110000000000
00000000000000000111110000000000
00000000000000000111110000000000
00000000000000000111110000000000
00000000000000001111000000000000
00000000000000001111100000000000
00000000000000001111100000000000
00000000000000011111000000000000
00000000000000001111000000000000
00000000000000011111000000000000
00000000000000011111000000000000
00000000000000011111100000000000
00000000000000001111100000000000
00000000000000001111000000000000
00000000000000000111000000000000
 4
"""


let labelledCharacter idx =
    let lines = digits.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
    let floats =
        lines.[idx * 33..idx * 33 + 31]
        |> Array.map (fun line -> line.ToCharArray() |> Array.map (string >> float))
        |> Array.concat
    let label = int <| lines.[idx * 33 + 32].Trim()
    floats, label

let labelledLetters digits =
    let rec loop idx current =
        try
            let next = labelledCharacter idx
            loop (idx + 1) (Array.append current [|next|])
        with
        | :? IndexOutOfRangeException -> current
    loop 0 [||]
namespace System
val digits : string

Full name: Script.digits
val labelledCharacter : idx:int -> float [] * int

Full name: Script.labelledCharacter
val idx : int
val lines : string []
String.Split([<ParamArray>] separator: char []) : string []
String.Split(separator: string [], options: StringSplitOptions) : string []
String.Split(separator: char [], options: StringSplitOptions) : string []
String.Split(separator: char [], count: int) : string []
String.Split(separator: string [], count: int, options: StringSplitOptions) : string []
String.Split(separator: char [], count: int, options: StringSplitOptions) : string []
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member Exit : exitCode:int -> unit
  static member ExitCode : int with get, set
  static member ExpandEnvironmentVariables : name:string -> string
  static member FailFast : message:string -> unit + 1 overload
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
  ...
  nested type SpecialFolder
  nested type SpecialFolderOption

Full name: System.Environment
property Environment.NewLine: string
String.ToCharArray() : char []
String.ToCharArray(startIndex: int, length: int) : char []
type StringSplitOptions =
  | None = 0
  | RemoveEmptyEntries = 1

Full name: System.StringSplitOptions
field StringSplitOptions.RemoveEmptyEntries = 1
val floats : float []
type Array =
  member Clone : unit -> obj
  member CopyTo : array:Array * index:int -> unit + 1 overload
  member GetEnumerator : unit -> IEnumerator
  member GetLength : dimension:int -> int
  member GetLongLength : dimension:int -> int64
  member GetLowerBound : dimension:int -> int
  member GetUpperBound : dimension:int -> int
  member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
  member Initialize : unit -> unit
  member IsFixedSize : bool
  ...

Full name: System.Array
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val line : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
val concat : arrays:seq<'T []> -> 'T []

Full name: Microsoft.FSharp.Collections.Array.concat
val label : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val labelledLetters : digits:'a -> (float [] * int) []

Full name: Script.labelledLetters
val digits : 'a
val loop : (int -> (float [] * int) [] -> (float [] * int) [])
val current : (float [] * int) []
val next : float [] * int
val append : array1:'T [] -> array2:'T [] -> 'T []

Full name: Microsoft.FSharp.Collections.Array.append
Multiple items
type IndexOutOfRangeException =
  inherit SystemException
  new : unit -> IndexOutOfRangeException + 2 overloads

Full name: System.IndexOutOfRangeException

--------------------
IndexOutOfRangeException() : unit
IndexOutOfRangeException(message: string) : unit
IndexOutOfRangeException(message: string, innerException: exn) : unit
Raw view New version

More information

Link:http://fssnip.net/kH
Posted:3 years ago
Author:mavnn
Tags: progfsharp