Skip to content

Conversation

@wojpok
Copy link
Collaborator

@wojpok wojpok commented Nov 5, 2025

This PR is part of #256 separated for easier merging and review

Copy link
Member

@ppolesiuk ppolesiuk left a comment

Choose a reason for hiding this comment

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

Looks good. I would consider defining min and max functions for any type with comparison.

lib/Prelude.fram Outdated
Comment on lines 54 to 55
pub let max (x : Int) (y : Int) =
if x > y then x else y
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to define this function for Int type only? Maybe we can define a more polymorphic version for any type with lt method.

Suggested change
pub let max (x : Int) (y : Int) =
if x > y then x else y
pub let max {T, method lt : T -> T ->> Bool} (x : T) (y : T) =
if x < y then y else x

BTW, we could add also min function, and provide some documentation for them.

lib/Prelude.fram Outdated
Comment on lines 59 to 60
pub let min {T, method gt : T -> T ->> Bool} (x : T) (y : T) =
if x > y then y else x
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to implement min and max functions on top of different comparison methods (lt and gt, respectively)? Both implementation can be based on lt method.

Suggested change
pub let min {T, method gt : T -> T ->> Bool} (x : T) (y : T) =
if x > y then y else x
pub let min {T, method lt : T -> T ->> Bool} (x : T) (y : T) =
if x < y then x else y

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought that it would be more accurate to return the first element when elements are equal. It may be not necessary. I will remove this later

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub let min {T, method gt : T -> T ->> Bool} (x : T) (y : T) =
if x > y then y else x
pub let min {T, method gt : T -> T ->> Bool} (x : T) (y : T) =
if y < x then y else x

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, right, my bad 😅

@wojpok
Copy link
Collaborator Author

wojpok commented Nov 12, 2025

Both min and max use lt method. Implementation have been supported with appropriate tests

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the Prelude library with additional utility functions and methods, supporting issue #256.

  • Adds min and max functions for comparable types
  • Adds strListCat for efficient string concatenation and replicate for string repetition
  • Exposes fst and snd as tuple methods
  • Adds map method to Option type

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/Prelude.fram Adds fst/snd methods, min/max comparison functions, strListCat extern, and replicate string utility
lib/Base/Option.fram Adds map method for functional transformation of Option values
test/stdlib/stdlib0006_Prelude.fram New test file covering min, max, strListCat, and replicate functions
test/stdlib/stdlib0001_Option.fram Adds test case for the new map method on Option type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ppolesiuk
Copy link
Member

Copilot have found some minor mistakes in comments, and its suggestions looks reasonable. If these things will be fixed, the PR will be ready for merge.

wojpok and others added 2 commits November 12, 2025 21:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@wojpok
Copy link
Collaborator Author

wojpok commented Nov 12, 2025

I have applied all suggestions directly

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +70 to +73
(let s' = replicate s (n / 2) in
s' + s')
else
(let s' = replicate s (n / 2) in
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: this line uses one space for indentation while the previous code uses two spaces. Should be indented with two spaces to match the rest of the file.

Suggested change
(let s' = replicate s (n / 2) in
s' + s')
else
(let s' = replicate s (n / 2) in
(let s' = replicate s (n / 2) in
s' + s')
else
(let s' = replicate s (n / 2) in

Copilot uses AI. Check for mistakes.
(let s' = replicate s (n / 2) in
s' + s')
else
(let s' = replicate s (n / 2) in
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: this line uses one space for indentation while the previous code uses two spaces. Should be indented with two spaces to match the rest of the file.

Suggested change
(let s' = replicate s (n / 2) in
(let s' = replicate s (n / 2) in

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ppolesiuk ppolesiuk merged commit c6b81a3 into fram-lang:master Nov 13, 2025
1 check passed
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.

2 participants