@@ -4,34 +4,35 @@ module GulpPurescript.OS
44 , platform
55 ) where
66
7- import Prelude ( class Show , (<$>), (<>), const )
7+ import Prelude
88
9- import Control.Monad.Eff (Eff )
9+ import Control.Monad.Eff (Eff , kind Effect )
1010import Control.Monad.Eff.Exception.Unsafe (unsafeThrow )
11+ import Control.Monad.Except (runExcept )
1112
1213import Data.Either (either )
13- import Data.Foreign (Foreign )
14- import Data.Foreign.Class (class IsForeign , read )
14+ import Data.Foreign (F , Foreign , readString )
1515import Data.Maybe (Maybe (..))
1616
17- foreign import data OS :: !
17+ foreign import data OS :: Effect
1818
1919data Platform = Darwin | Linux | Win32
2020
2121instance showPlatform :: Show Platform where
22- show a = case a of
23- Darwin -> " darwin"
24- Linux -> " linux"
25- Win32 -> " win32"
26-
27- instance isForeignPlatform :: IsForeign Platform where
28- read a = (\a -> case a of
29- " darwin" -> Darwin
30- " linux" -> Linux
31- " win32" -> Win32
32- _ -> unsafeThrow (" Unhandled platform: " <> a)) <$> read a
22+ show = case _ of
23+ Darwin -> " darwin"
24+ Linux -> " linux"
25+ Win32 -> " win32"
26+
27+ readPlatform :: Foreign -> F Platform
28+ readPlatform =
29+ readString >=> case _ of
30+ " darwin" -> pure Darwin
31+ " linux" -> pure Linux
32+ " win32" -> pure Win32
33+ a -> unsafeThrow (" Unhandled platform: " <> a)
3334
3435platform :: forall eff . Eff (os :: OS | eff ) (Maybe Platform )
35- platform = either (const Nothing ) Just <$> read <$> platformFn
36+ platform = either (const Nothing ) Just <$> runExcept <$> readPlatform <$> platformFn
3637
3738foreign import platformFn :: forall eff . Eff (os :: OS | eff ) Foreign
0 commit comments