Skip to content

Commit 650610e

Browse files
Nick SeagullNickSeagull
andauthored
v0.3.0 - Triggers and renaming (#103)
* Start working in subscriptions * Implement basic subscriptions type * Remove unused import * Update * update * Update * Fix format * Rename command to action * Rename to service * Change FIXME comment * Refactor * Rename msg to event * Update * Update readme --------- Co-authored-by: NickSeagull <[email protected]>
1 parent 9dae30a commit 650610e

File tree

16 files changed

+557
-420
lines changed

16 files changed

+557
-420
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"fprint",
1111
"GADT",
1212
"Monoid",
13+
"Nanotime",
1314
"NEOHASKELL",
1415
"NOINLINE",
1516
"optparse",
1617
"OVERLAPPABLE",
18+
"Posix",
1719
"reldir",
1820
"relfile",
1921
"Semigroup",
@@ -23,4 +25,4 @@
2325
],
2426
"haskell.manageHLS": "PATH",
2527
"nixEnvSelector.nixFile": "${workspaceFolder}/devenv.nix"
26-
}
28+
}

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111

1212
---
1313

14-
# Welcome
15-
16-
This is where the NeoHaskell code will live, once the implementation begins.
17-
18-
If you're confused, this is because the project prioritizes the design and documentation first, and only implementation afterwards!
19-
20-
Take a look at the [GitHub Milestones page](https://github.com/neohaskell/NeoHaskell/milestones) for a rough plan for the implementation.
21-
22-
Design documents are being worked on currently for sharing progress in a stable way with the community. Sorry for the inconvenience! 🙏
23-
24-
<!--
2514
# Welcome to the contributor guide
2615

2716
If you want to learn about NeoHaskell itself, checkout
@@ -35,27 +24,24 @@ different parts of NeoHaskell.
3524

3625
# Installing the required tools
3726

38-
- Install GHCUP by following [the official instructions](https://www.haskell.org/ghcup/).
39-
- Run `ghcup tui` and press `s` on the following options:
40-
- GHC 9.2.8
41-
- Cabal 3.10.1.0
42-
- HLS 2.2.0.0
43-
- (When prompted for download, press `y` to accept)
27+
(This assumes that you're using MacOS, WSL2 or Linux)
28+
29+
- Install DevEnv by following [the official instructions](https://devenv.sh/getting-started/).
30+
- Run `devenv shell`
31+
- Run `cabal update && cabal build all`
4432

4533
The recommended IDE for any NeoHaskell project is [Visual Studio Code](https://code.visualstudio.com/).
4634

4735
# Get the code
4836

4937
- Fork this repository
5038
- `git clone <url to your fork>`
51-
- `cd neohaskell && code .`
39+
- `cd NeoHaskell && code .`
5240

5341
# Install the recommended extensions
5442

5543
When opening the project for the first time, you will be prompted to install the recommended extensions, install them.
5644

57-
-->
58-
5945
# Collaborate on Discord
6046

6147
It's always better to hack with people, so why not join the [Discord server](https://discord.gg/invite/wDj3UYzec8)?

cli/src/Neo.hs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,115 @@
22

33
module Neo (main) where
44

5-
import Command qualified
5+
import Action qualified
6+
import Array qualified
67
import Core
78
import File qualified
8-
import Platform qualified
99
import Result qualified
10+
import Service qualified
1011
import ToText (Show)
12+
import Time qualified
1113
import Yaml qualified
1214

15+
1316
type Model =
1417
Record
1518
'[ "project" := Maybe ProjectDefinition,
1619
"path" := Maybe Path,
20+
"count" := Int,
1721
"status" := Text
1822
]
1923

24+
2025
type ProjectDefinition =
2126
Record
2227
'[ "name" := Text,
2328
"version" := Version
2429
]
2530

26-
data Message
31+
32+
data Event
2733
= ProjectFileRead Text
2834
| ProjectFileAccessErrored File.Error
2935
| ProjectFileParsed ProjectDefinition
3036
| BuildStarted
37+
| Tick
3138
| BuildFailed FailureReason
3239
deriving (Show)
3340

41+
3442
data FailureReason
3543
= ProjectFileParseError Text
3644
deriving (Show)
3745

38-
init :: (Model, Command Message)
46+
47+
init :: (Model, Action Event)
3948
init = do
4049
let emptyModel =
4150
ANON
4251
{ project = Nothing,
4352
path = Nothing,
53+
count = 0,
4454
status = "Starting up"
4555
}
46-
let command =
56+
let action =
4757
File.readText
4858
ANON
4959
{ path = [path|project.yaml|],
5060
onSuccess = ProjectFileRead,
5161
onError = ProjectFileAccessErrored
5262
}
53-
(emptyModel, command)
63+
(emptyModel, action)
64+
5465

55-
update :: Message -> Model -> (Model, Command Message)
56-
update message model =
57-
case message of
66+
update :: Event -> Model -> (Model, Action Event)
67+
update event model =
68+
case event of
5869
ProjectFileRead fileContent -> do
5970
let parsedContent = Yaml.parse fileContent
6071
let newModel = model {status = "Parsing project file"}
6172
case parsedContent of
6273
Result.Ok projectDefinition ->
63-
(newModel, Command.continueWith (ProjectFileParsed projectDefinition))
74+
(newModel, Action.continueWith (ProjectFileParsed projectDefinition))
6475
Result.Err _ -> do
6576
let error = ProjectFileParseError fileContent
66-
(newModel, Command.continueWith (BuildFailed error))
77+
(newModel, Action.continueWith (BuildFailed error))
6778
ProjectFileAccessErrored _ ->
68-
(model {status = "File Access Errored"}, Command.none)
79+
(model {status = "File Access Errored"}, Action.none)
6980
ProjectFileParsed projectDefinition ->
70-
(model {project = Just projectDefinition}, Command.none)
81+
(model {project = Just projectDefinition}, Action.none)
7182
BuildStarted ->
72-
(model {status = "Build Started!"}, Command.none)
83+
(model {status = "Build Started!"}, Action.none)
7384
BuildFailed _ ->
74-
(model {status = "Build Failed!"}, Command.none)
85+
(model {status = "Build Failed!"}, Action.none)
86+
Tick ->
87+
( model
88+
{ count = model.count + 1,
89+
status = "Count: " ++ toText model.count
90+
},
91+
Action.none
92+
)
93+
7594

7695
view :: Model -> Text
7796
view m =
7897
case m.project of
7998
Just project ->
80-
toText project
99+
m.status ++ "\n\n" ++ toText project
81100
Nothing ->
82101
m.status
83102

103+
84104
main :: IO ()
85-
main = Platform.init (ANON {init = init, view = view, update = update})
105+
main =
106+
Service.init
107+
( ANON
108+
{ init = (init),
109+
view = (view),
110+
triggers =
111+
Array.fromLinkedList
112+
[ Time.triggerEveryMilliseconds 1000 (\_ -> Tick)
113+
],
114+
update = (update)
115+
}
116+
)

core/concurrency/AsyncIO.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import Basics
44
import Control.Concurrent qualified as Ghc
55
import Control.Concurrent.Async qualified as GhcAsync
66

7+
78
type AsyncIO result = GhcAsync.Async result
89

10+
911
run :: IO result -> IO (AsyncIO result)
1012
run = GhcAsync.async
1113

14+
1215
waitFor :: AsyncIO result -> IO result
1316
waitFor = GhcAsync.wait
1417

18+
1519
sleep :: Int -> IO Unit
16-
sleep microseconds = Ghc.threadDelay microseconds
20+
sleep milliseconds = Ghc.threadDelay (milliseconds * 1000)

core/core/Basics.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ module Basics
119119
Control.Monad.join,
120120
Type,
121121
ifThenElse,
122+
Control.Monad.forever,
122123
)
123124
where
124125

core/core/Core.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ module Core (
55
module Reexported,
66
) where
77

8+
import Action as Reexported (Action)
89
import Appendable as Reexported ((++))
910
import Basics as Reexported
1011
import Char as Reexported (Char)
11-
import Command as Reexported (Command)
1212
import ConcurrentVar as Reexported (ConcurrentVar)
1313
import Console as Reexported (print, readLine)
1414
import Default as Reexported (Default (..), defaultValue)
@@ -18,10 +18,11 @@ import LinkedList as Reexported (LinkedList)
1818
import Map as Reexported (Map)
1919
import Maybe as Reexported (Maybe (..))
2020
import Path as Reexported (Path, path)
21-
import Platform as Reexported (Platform)
2221
import Result as Reexported (Result)
22+
import Service as Reexported (Service)
2323
import Text as Reexported (Text)
2424
import ToText as Reexported (ToText, toText)
25+
import Trigger as Reexported (Trigger)
2526
import Unknown as Reexported (Unknown)
2627
import Var as Reexported (Var)
2728
import Version as Reexported (Version, version)

core/nhcore.cabal

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ common common_cfg
3333
containers,
3434
opt-env-conf,
3535
path,
36+
nanotime,
3637
process,
3738
large-anon,
3839
pretty-simple,
@@ -80,18 +81,21 @@ library
8081
Unit,
8182
Tuple,
8283
Console,
83-
Subprocess,
8484
Int,
8585
IO,
86-
Path,
87-
File,
8886
Maybe,
8987
Array,
9088
Version,
9189
Record,
9290
Unknown,
9391
Var,
9492

93+
-- System
94+
File,
95+
Subprocess,
96+
Path,
97+
Time,
98+
9599
-- OptionsParser
96100
OptionsParser,
97101

@@ -110,10 +114,11 @@ library
110114
Thenable,
111115
ToText,
112116

113-
-- Platform
114-
Command,
117+
-- Service
118+
Action,
115119
Html,
116-
Platform,
120+
Service,
121+
Trigger,
117122

118123
-- Concurrency
119124
AsyncIO,
@@ -126,10 +131,11 @@ library
126131
hs-source-dirs:
127132
core,
128133
concurrency,
129-
platform,
134+
service,
130135
json,
131136
yaml,
132137
traits,
138+
system,
133139
options-parser
134140
default-language: GHC2021
135141

0 commit comments

Comments
 (0)