Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prelude split into multiple files #133

Merged
merged 2 commits into from
Jun 20, 2024
Merged

Prelude split into multiple files #133

merged 2 commits into from
Jun 20, 2024

Conversation

ppolesiuk
Copy link
Member

Now the Prelude is split into several files. The two most notable files are Base/Types with some standard types and Base/Operators with some standard operators. Each of other files contains only methods that should be visible without importing anything. There is no Base/List file with standard methods on list. The user must import List module by himself.

Other minor changes are the following:

  • Added LICENSE header in each library file
  • Added comparison operators for Bool type
  • Removed makeString method (function?), as it seemed broken.

Fixes #129 and #132

Now the Prelude is split into several files. The two most notable files
are `Base/Types` with some standard types and `Base/Operators` with some
standard operators. Each of other files contains only methods that
should be visible without importing anything. There is no `Base/List`
file with standard methods on list. The user must import `List` module
by himself.

Other minor changes are the following:
- Added LICENSE header in each library file
- Added comparison operators for Bool type
- Removed `makeString` method (function?), as it seemed broken.
@ppolesiuk ppolesiuk requested a review from Foxinio June 16, 2024 19:24
@ppolesiuk ppolesiuk linked an issue Jun 16, 2024 that may be closed by this pull request
Copy link
Collaborator

@Foxinio Foxinio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote some changes and suggestions. One things that struck out are, it's really hard to test functions that use `re implicit.

lib/Base/Char.fram Outdated Show resolved Hide resolved
lib/Base/Int.fram Show resolved Hide resolved
pub method fn (>>) = shiftr
pub method fn (>>>) = ashiftr

pub method fn (:=) = set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we would want some unary operator for get? Ocaml's (! .) works fine for me but maybe there is a better one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it. The nice thing about unary operator (! .) in OCaml is that it is a) short, and b) it has very high precedence (higher than application). I think a method get also has both of these advantages. Moreover, I see the two arguments against OCaml-like (! .):

  1. it misleadingly resembles negation in some languages (like C)
  2. it introduces some problems with operator lexing: ! and != starts with the same character, but have very different precedence (see PR Fix != operator in lexer #125).

pub let charListToStr = (extern dbl_chrListToStr : List Char -> String)

pub method code {self : Char} =
extern dbl_chrCode : Char -> Int

pub let chr {`re : {type X} -> Unit ->[|_] X} (n : Int) =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a user i would expect to see function like this in Char module, and also those modules are a good place to add any functions (not only methods) attached to these types, but not necessarily being dependent on any value of this type. Such as chr function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. However, I'm against moving it into /Base/Char/ as the main purpose of this module is to contain methods that might be used without importing Char explicitly. We should create a separate module Char for that. I thing it can be done as a separate task.

pub method le = (extern dbl_leStr : String -> String -> Bool) self

pub method length = (extern dbl_strLen : String -> Int) self
pub method get {`re : {type X} -> Unit ->[|_] X, self : String} (n : Int) =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are thinking of adding arrays, and there accessor to specyfic element of array is method at, maybe its a good idea to keep consistency and also name this method at

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In arrays (#126) the at accessor is only for writing. Just to be able to write code like arr.at 42 := 13. For reading we have get. I don't see how to define a single accessor for both reading and writing.

import /Base/Bool
import /Base/Int
import /Base/Char
import /Base/String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will add more functionality to String module, and then i would expect to access that functionality with import String instead of having to write import /Base/String in repl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I answered to chr issue, the purpose of /Base/String is to have only some basic methods there. For other functions I would prefer to have a separate String module.

@ppolesiuk
Copy link
Member Author

One things that struck out are, it's really hard to test functions that use `re implicit.

Yes, I also noticed that. There is a separate issue on that (#131).

@ppolesiuk ppolesiuk requested a review from Foxinio June 19, 2024 07:38
Copy link
Collaborator

@Foxinio Foxinio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see any more issues

@ppolesiuk ppolesiuk merged commit b826745 into master Jun 20, 2024
2 checks passed
@ppolesiuk ppolesiuk deleted the multiple-prelude-files branch June 20, 2024 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split Prelude into multiple files LICENSE headers in stdlib files
2 participants