Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MLG360Interpreter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
MLG360Interpreter
Commits
67ec309e
Commit
67ec309e
authored
2 years ago
by
plw1g21
Browse files
Options
Downloads
Patches
Plain Diff
Added a frame haskell file just to see if it looks more suitable than
the hashmap
parent
6e7bfef2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
JFrame.hs
+23
-0
23 additions, 0 deletions
JFrame.hs
JHashMap.hs
+15
-14
15 additions, 14 deletions
JHashMap.hs
with
38 additions
and
14 deletions
JFrame.hs
0 → 100644
+
23
−
0
View file @
67ec309e
type
Frame
a
=
[(
String
,
a
)]
-- Create a new frame with an empty list of key-value pairs
newFrame
::
Frame
a
newFrame
=
[]
-- Add a new key-value pair to the frame
addToFrame
::
String
->
a
->
Frame
a
->
Frame
a
addToFrame
key
value
frame
=
(
key
,
value
)
:
frame
-- Lookup the value associated with a key in the frame
lookupInFrame
::
String
->
Frame
a
->
Maybe
a
lookupInFrame
_
[]
=
Nothing
lookupInFrame
key
((
k
,
v
)
:
xs
)
|
key
==
k
=
Just
v
|
otherwise
=
lookupInFrame
key
xs
-- Update the value associated with a key in the frame
updateInFrame
::
String
->
a
->
Frame
a
->
Frame
a
updateInFrame
_
_
[]
=
[]
updateInFrame
key
value
((
k
,
v
)
:
xs
)
|
key
==
k
=
(
k
,
value
)
:
xs
|
otherwise
=
(
k
,
v
)
:
updateInFrame
key
value
xs
This diff is collapsed.
Click to expand it.
JHashMap.hs
+
15
−
14
View file @
67ec309e
import
qualified
Data.Map
as
Map
import
qualified
Data.Map
as
Map
import
Data.IORef
import
Data.IORef
type
MutableMap
a
=
IORef
(
Map
.
Map
String
a
)
newMap
::
IO
(
MutableMap
a
)
newMap
=
newIORef
Map
.
empty
insertMap
::
MutableMap
a
->
String
->
a
->
IO
()
insertMap
ref
key
value
=
modifyIORef'
ref
(
Map
.
insert
key
value
)
lookupMap
::
MutableMap
a
->
String
->
IO
(
Maybe
a
)
lookupMap
ref
key
=
Map
.
lookup
key
<$>
readIORef
ref
main
::
IO
()
main
::
IO
()
main
=
do
main
=
do
-- Create a new mutable map
-- Create a new mutable map
julioHashMap
<-
newMap
julioHashMap
<-
newMap
-- insertMap will be called whenever an EqualsToken is located
-- insertMap will be called whenever an EqualsToken is located
insertMap
julioHashMap
"tile1"
"valuesLoadedIn1"
-- insertMap should be able to take in any value in the key-pair value
insertMap
julioHashMap
"tile2"
"42"
insertMap
julioHashMap
"tile2"
(
1
::
Int
)
insertMap
julioHashMap
"tile1"
"example"
-- When a variable name is seen and not an equals, use "lookupMap"
-- When a variable name is seen and not an equals, use "lookupMap"
...
@@ -19,15 +32,3 @@ main = do
...
@@ -19,15 +32,3 @@ main = do
-- Temporary just to check if working
-- Temporary just to check if working
putStrLn
$
"tile1: "
++
show
val1
putStrLn
$
"tile1: "
++
show
val1
putStrLn
$
"tile2: "
++
show
val2
putStrLn
$
"tile2: "
++
show
val2
type
MutableMap
a
=
IORef
(
Map
.
Map
String
a
)
newMap
::
IO
(
MutableMap
a
)
newMap
=
newIORef
Map
.
empty
insertMap
::
MutableMap
a
->
String
->
a
->
IO
()
insertMap
ref
key
value
=
modifyIORef'
ref
(
Map
.
insert
key
value
)
lookupMap
::
MutableMap
a
->
String
->
IO
(
Maybe
a
)
lookupMap
ref
key
=
Map
.
lookup
key
<$>
readIORef
ref
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment