Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7f21e72
Ordered Map and Ordered Set
MinionJakub Jun 19, 2024
4d6a53a
Update OrderedMap.fram
MinionJakub Jun 20, 2024
c017c3c
Merge branch 'fram-lang:master' into master
MinionJakub Jun 21, 2024
ef1d14f
Implementation of Queues
MinionJakub Jun 21, 2024
8bcd905
Testing files for Map, Set, Queues.
MinionJakub Jun 21, 2024
27ff11e
Update OrderedMap.fram
MinionJakub Jun 21, 2024
dae76bc
Changes to implementation and tests
MinionJakub Aug 14, 2024
e5d206f
Adding missing files
MinionJakub Aug 14, 2024
ce31a6d
Merge branch 'fram-lang:master' into master
MinionJakub Aug 14, 2024
5b3cd88
Correcting a test file
MinionJakub Aug 15, 2024
eb36254
Correcting definitions
MinionJakub Oct 29, 2024
274f324
Changing from [E] in [|E]
MinionJakub Oct 29, 2024
8584322
Correcting style and renaming few things
MinionJakub Nov 20, 2024
9aa2f4a
Merge branch 'fram-lang:master' into master
MinionJakub Nov 28, 2024
7bb419d
Correcting a lot of things mainly coding style
MinionJakub Nov 28, 2024
bb826df
Changing tests and adding assert to prelude
MinionJakub Nov 28, 2024
a3f0b7b
little changes
MinionJakub Nov 30, 2024
c44f26c
Moving things from Ord and adding fromList and toList to Queue
MinionJakub Dec 3, 2024
b9eb957
onError methods
MinionJakub Dec 3, 2024
88ee81d
correcting test for names changes
MinionJakub Dec 3, 2024
6727f66
little change
MinionJakub Dec 3, 2024
e462f83
Merge branch 'fram-lang:master' into master
MinionJakub Dec 16, 2024
9ade649
Small changes
MinionJakub Feb 20, 2025
2904ee7
Adding comments
MinionJakub Feb 20, 2025
9dc0c0c
Merge branch 'fram-lang:master' into master
MinionJakub Feb 20, 2025
7469061
Some (hopefully) final changes
Foxinio Mar 12, 2025
c4675a9
Replacing '\t' with ' '
Foxinio Mar 12, 2025
cd894b1
Final touches before merge by Foxinio
MinionJakub Mar 13, 2025
8f31eb6
Fix file permissions
forell Mar 25, 2025
ec465d9
Merge branch 'fram-lang:master' into master
MinionJakub Apr 3, 2025
394a919
Correction due to change in syntax
MinionJakub Apr 4, 2025
dd86d99
Merge branch 'fram-lang:master' into master
MinionJakub Jun 30, 2025
5450ed1
Correcting small mistakes and adding some longly requested papers and…
MinionJakub Jul 3, 2025
f9ccbf0
Merge branch 'fram-lang:master' into master
MinionJakub Jul 6, 2025
b447f1e
Merge branch 'fram-lang:master' into master
MinionJakub Oct 23, 2025
2549f93
Changing to incremental changes - for now queues + red-black tree
MinionJakub Oct 23, 2025
da11171
Merge branch 'master' into master
MinionJakub Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Base/Types.fram
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ pub data Pair X Y = (,) of X, Y

pub data Either X Y = Left of X | Right of Y

pub data Ordered = Lt | Eq | Gt

pub data Result A E = Ok of A | Err of E
1 change: 1 addition & 0 deletions lib/Prelude.fram
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ pub module Int64
pub let one = 1L
pub let ofInt (n : Int) = n.toInt64
end

144 changes: 144 additions & 0 deletions lib/Queue.fram
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{# This file is part of DBL, released under MIT license.
# See LICENSE for details.
#}

import List

data NotNegativeInt = Zero | Positive of Int

let addOne value =
match value with
| Zero => Positive 1
| Positive n => Positive (n+1)
end

let subOne value =
match value with
| Zero => Zero
| Positive n => if n == 1 then Zero else Positive (n-1)
end

data RotationState Val =
| Idle
| Reversing of NotNegativeInt, List Val, List Val, List Val, List Val
| Appending of NotNegativeInt, List Val, List Val
| Done of List Val

data HoodMelvilleQueue Val =
Copy link
Collaborator

Choose a reason for hiding this comment

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

This type should be abstract. As is right now, it can't be used to annotate stuff outside this module. Also, name could be shorter, maybe HMQueue or just plain and simple Queue?

| HMQueue of NotNegativeInt, List Val, RotationState Val,
NotNegativeInt, List Val
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation: line 29 should align with the opening parameter on line 28. The second line of the constructor parameters uses 1 space instead of 3 spaces for proper alignment.

Suggested change
NotNegativeInt, List Val
NotNegativeInt, List Val

Copilot uses AI. Check for mistakes.

let exec state =
match state with
| Reversing ok (x::f) f' (y::r) r' =>
Reversing (addOne ok) f (x::f') r (y::r')
| Reversing ok [] f' [y] r' => Appending ok f' (y::r')
| Appending Zero f' r' => Done r'
| Appending ok (x::f') r' => Appending (subOne ok) f' (x::r')
| _ => state
end

let invalidate state =
match state with
| Reversing ok f f' r r' => Reversing (subOne ok) f f' r r'
| Appending Zero f' (x::r') => Done r'
| Appending ok f' r' => Appending (subOne ok) f' r'
| _ => state
end

let execTwice hmqueue =
match hmqueue with
| HMQueue lenf f state lenr r =>
match exec (exec state) with
| Done newf => HMQueue lenf newf Idle lenr r
| newstate => HMQueue lenf f newstate lenr r
end
end

let leq v1 v2 =
match (v1,v2) with
| (Zero,Zero) => True
| (Zero,Positive _) => True
| (Positive _, Zero) => False
| (Positive n, Positive m) => n <= m
end

let add v1 v2 =
match (v1,v2) with
| (Zero,any) => any
| (any,Zero) => any
| (Positive n, Positive m) => Positive (n+m)
end

let check queue =
match queue with
| HMQueue lenf f state lenr r =>
if leq lenr lenf then execTwice queue
else (
let newstate = Reversing Zero f [] r [] in
execTwice (HMQueue (add lenf lenr) f newstate Zero [])
)
end

pub let emptyQueue = HMQueue Zero [] Idle Zero []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not empty?

pub let isEmpty queue =
match queue with
| HMQueue Zero _ _ _ _ => True
| _ => False
end

let snoc queue value =
match queue with
| HMQueue lenf f state lenr r =>
check (HMQueue lenf f state (addOne lenr) (value :: r))
end

let head queue =
match queue with
| HMQueue Zero _ _ _ _ => None
| HMQueue _ (x::xs) _ _ _ => Some x
| _ => impossible ()
end

let tail queue =
match queue with
| HMQueue Zero _ _ _ _ => emptyQueue
| HMQueue _ [] _ _ _ => emptyQueue
| HMQueue lenf (x::xs) state lenr r =>
check (HMQueue (subOne lenf) xs (invalidate state) lenr r)
end

let mapRotationState f state =
match state with
| Idle => Idle
| Done list => Done (List.map f list)
| Appending v list1 list2 =>
Appending v (List.map f list1) (List.map f list2)
| Reversing v list1 list2 list3 list4 =>
Reversing v (List.map f list1) (List.map f list2)
(List.map f list3) (List.map f list4)
end

let mapQueue queue f =
match queue with
Copy link
Collaborator

Choose a reason for hiding this comment

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

just like in fold function: you have to respect element count. In case a function f is a partial function, there may be edge cases where you terminate a program on a value that shouldn't be in queue. We don't need this function, composition of toList > map > fromList should be enough.

| HMQueue v1 list1 state v2 list2 =>
HMQueue v1 (List.map f list1)
(mapRotationState f state) v2 (List.map f list2)
end

let rec toList queue =
match head queue with
| None => []
| Some x => x :: toList (tail queue)
end

pub let fromList list = List.foldLeft snoc emptyQueue list

pub method isEmpty self = isEmpty self
pub method snoc self = snoc self
pub method tail self = tail self
pub method push self = snoc self
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remane this to cons. Push is confusing.

pub method pop self = tail self
pub method head self = head self
pub method map self = mapQueue self
pub method toList self = toList self
Loading