File tree Expand file tree Collapse file tree 2 files changed +49
-3
lines changed
Expand file tree Collapse file tree 2 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 1+ -- | This module defines data type for the different platforms supported by
2+ -- | Node.js
3+ module Node.Platform where
4+
5+ import Prelude
6+ import Data.Function (on )
7+ import Data.Maybe (Maybe (..))
8+
9+ data Platform
10+ = Darwin
11+ | FreeBSD
12+ | Linux
13+ | SunOS
14+ | Win32
15+
16+ -- | The String representation for a platform, recognised by Node.js.
17+ toString :: Platform -> String
18+ toString Darwin = " darwin"
19+ toString FreeBSD = " freebsd"
20+ toString Linux = " linux"
21+ toString SunOS = " sunos"
22+ toString Win32 = " win32"
23+
24+ fromString :: String -> Maybe Platform
25+ fromString " darwin" = Just Darwin
26+ fromString " freebsd" = Just FreeBSD
27+ fromString " linux" = Just Linux
28+ fromString " sunos" = Just SunOS
29+ fromString " win32" = Just Win32
30+ fromString _ = Nothing
31+
32+ instance showPlatform :: Show Platform where
33+ show Darwin = " Darwin"
34+ show FreeBSD = " FreeBSD"
35+ show Linux = " Linux"
36+ show SunOS = " SunOS"
37+ show Win32 = " Win32"
38+
39+ instance eqPlatform :: Eq Platform where
40+ eq = eq `on` toString
41+
42+ instance ordPlatform :: Ord Platform where
43+ compare = compare `on` toString
Original file line number Diff line number Diff line change @@ -26,12 +26,15 @@ import Prelude
2626import Control.Monad.Eff
2727import Control.Monad.Eff.Console (CONSOLE ())
2828import Control.Monad.Eff.Exception (EXCEPTION ())
29- import Control.Monad.Eff.Unsafe (unsafePerformEff )
3029import Data.Maybe (Maybe ())
30+ import Data.Maybe.Unsafe (fromJust )
3131import Data.StrMap (StrMap ())
3232import Data.StrMap as StrMap
3333import Node.Stream (Readable (), Writable ())
3434
35+ import Node.Platform (Platform ())
36+ import Node.Platform as Platform
37+
3538-- | An effect tracking interaction with the global `process` object.
3639foreign import data PROCESS :: !
3740
@@ -94,8 +97,8 @@ foreign import setEnv :: forall eff. String -> String -> Eff (process :: PROCESS
9497pid :: Int
9598pid = process.pid
9699
97- platform :: String
98- platform = process.platform
100+ platform :: Platform
101+ platform = fromJust ( Platform .fromString process.platform)
99102
100103-- | Cause the process to exit with the supplied integer code. An exit code
101104-- | of 0 is normally considered successful, and anything else is considered a
You can’t perform that action at this time.
0 commit comments