3 people like it.

Detect operating system

Detect Linux, OSX, or Windows with a handy discriminated union

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
open System

type OS =
        | OSX            
        | Windows
        | Linux

let getOS = 
        match int Environment.OSVersion.Platform with
        | 4 | 128 -> Linux
        | 6       -> OSX
        | _       -> Windows
namespace System
type OS =
  | OSX
  | Windows
  | Linux

Full name: Script.OS
union case OS.OSX: OS
Multiple items
union case OS.Windows: OS

--------------------
namespace System.Windows
union case OS.Linux: OS
val getOS : OS

Full name: Script.getOS
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<_>
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.OSVersion: OperatingSystem
property OperatingSystem.Platform: PlatformID
Raw view Test code New version

More information

Link:http://fssnip.net/7OP
Posted:7 years ago
Author:Jack Mott
Tags: linux , osx , windows