-
Notifications
You must be signed in to change notification settings - Fork 20
/
Platform.purs
54 lines (48 loc) · 1.41 KB
/
Platform.purs
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
-- | This module defines data type for the different platforms supported by
-- | Node.js
module Node.Platform where
import Prelude
import Data.Maybe (Maybe(..))
-- | See [the Node docs](https://nodejs.org/dist/latest-v6.x/docs/api/os.html#os_os_platform).
data Platform
= AIX
| Darwin
| FreeBSD
| Linux
| OpenBSD
| SunOS
| Win32
| Android
-- | The String representation for a platform, recognised by Node.js.
toString :: Platform -> String
toString AIX = "aix"
toString Darwin = "darwin"
toString FreeBSD = "freebsd"
toString Linux = "linux"
toString OpenBSD = "openbsd"
toString SunOS = "sunos"
toString Win32 = "win32"
toString Android = "android"
-- | Attempt to parse a `Platform` value from a string, in the format returned
-- | by Node.js' `process.platform`.
fromString :: String -> Maybe Platform
fromString "aix" = Just AIX
fromString "darwin" = Just Darwin
fromString "freebsd" = Just FreeBSD
fromString "linux" = Just Linux
fromString "openbsd" = Just OpenBSD
fromString "sunos" = Just SunOS
fromString "win32" = Just Win32
fromString "android" = Just Android
fromString _ = Nothing
instance showPlatform :: Show Platform where
show AIX = "AIX"
show Darwin = "Darwin"
show FreeBSD = "FreeBSD"
show Linux = "Linux"
show OpenBSD = "OpenBSD"
show SunOS = "SunOS"
show Win32 = "Win32"
show Android = "Android"
derive instance eqPlatform :: Eq Platform
derive instance ordPlatform :: Ord Platform