Conversation
src/demo.re
Outdated
| | Er | ||
| | Ir; | ||
|
|
||
| let getSubjectVariant subject => { |
There was a problem hiding this comment.
Typically in Reason you would group together a type and its main operations into a single module. E.g.:
module Subject = {
/* The type name becomes just `t` to avoid repetition when accessed from outside the module */
type t =
| Yo
| Tu
| Ella
| Nosotras
| Vosotras
| Ellas;
let ofString =
fun
| "yo" => Yo
| "tu" => Tu
| "ella" => Ella
| "nosotras" => Nosotras
| "vosotras" => Vosotras
| _ => Ellas;
};... and similarly for the ending type. Then you'd be able to use them like Subject.ofString, Ending.ofString. It makes the API uniform.
src/demo.re
Outdated
|
|
||
| let genPresentEnding ending subject => { | ||
| Js.log("subject", subject); | ||
| switch subject { |
There was a problem hiding this comment.
So one of the really cool things about Reason pattern matching is you can match on multiple things at the same time. E.g.,
switch (subject, ending) {
| (Yo, _) => "yo"
| (Tu, Ar) => "as"
| (Tu, _) => "es"
| (Ella, Ar) => "a"
| (Ella, _) => "e"
| (Nosotras, _) => "amos"
| (Vosotras, _) => "\195\161is" /* Reason source code is not Unicode, btw */
| (Ellas, _) => "an"
};This keeps your matches really nice and flat.
| @@ -0,0 +1,38 @@ | |||
| { | |||
There was a problem hiding this comment.
This file should be inside the .vscode directory
There was a problem hiding this comment.
I'm not using visual studio (pure vim), so therefore do not have .vscode directory. Any better folder to place this in, or should I have not committed this file?
There was a problem hiding this comment.
Oh, if you're not using Visual Studio Code, you don't need this. This is like a per-project .vimrc but for VSCode.
| }; | ||
|
|
||
| let conjugate word info => { | ||
| let start = ( String.length word ) - 2; |
There was a problem hiding this comment.
Function application 'binds more tightly' than operator application, so you can write String.length word - 2
|
|
||
| let genFutureEnding ending subject => { | ||
| switch (subject:Subject.t, ending:Ending.t) { | ||
| | (Yo, _) => "\130" |
There was a problem hiding this comment.
You can use the {js| ... |js} technique here as well for Unicode.
| }; | ||
|
|
||
| let genPresentEnding ending subject => { | ||
| switch (subject:Subject.t, ending:Ending.t) { |
There was a problem hiding this comment.
You don't really need the type annotations, Reason will infer them 😊
No description provided.