Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
prog3-coursework
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ik1g19
prog3-coursework
Commits
fd638c3c
Commit
fd638c3c
authored
4 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
progress on challenge 4
parent
14d63f3c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cw/src/Challenges.hs
+45
-18
45 additions, 18 deletions
cw/src/Challenges.hs
with
45 additions
and
18 deletions
cw/src/Challenges.hs
+
45
−
18
View file @
fd638c3c
...
...
@@ -278,8 +278,8 @@ prettyPrint (LamDef ms e) = exprBrackets e
--applies brackets to expr if needed
exprBrackets
::
LamExpr
->
String
exprBrackets
e
|
expr
str
==
e
=
str
--omit brackets
|
otherwise
=
"("
+
str
++
")"
--include brackets
exprBrackets
e
|
fst
(
head
(
parse
expr
str
))
==
e
=
str
--omit brackets
|
otherwise
=
"("
+
+
str
++
")"
--include brackets
where
str
=
exprToStr
e
...
...
@@ -318,36 +318,63 @@ ex3'4 = LamDef [ ("F", LamAbs 1 (LamVar 1) ) ] (LamAbs 2 (LamApp (LamAbs 1 (LamV
parseLamMacro
::
String
->
Maybe
LamMacroExpr
parseLamMacro
_
=
Nothing
parseLamMacro
str
|
parsed
==
[]
=
Nothing
|
otherwise
=
Just
parsed
where
parsed
=
fst
(
head
(
parse
(
macroExpr
[]
)
str
))
--HEAD WILL NOT WORK
macroExpr
::
[
(
String
,
LamExpr
)
]
->
Parser
LamMacroExpr
macroExpr
ms
=
do
string
"def"
name
<-
token
macroName
symbol
"="
e
<-
token
expr
token
$
string
"in"
macros
<-
macroExpr
$
ms
++
[(
name
,
e
)]
return
$
macros
<|>
do
e
<-
token
expr
return
$
LamDef
ms
e
macroExpr
::
Parse
LamMacroExpr
macroExpr
=
do
string
"def"
name
<-
token
macroName
symbol
"="
e
<-
token
expr
string
"in"
macro
<-
many
macroExpr
return
$
LamDef
[(
name
,
e
)]
-- macroExpr :: Parse LamMacroExpr
-- macroExpr = do string "def"
-- name <- token macroName
-- symbol "="
-- e <- token expr
-- token $ string "in"
-- macros <- macroLoop
-- return $ LamDef macros
-- where
-- macroLoop :: Parse [(String,LamExpr)]
-- macroLoop = do string "def"
-- name <- token macroName
-- symbol "="
-- e <- token expr
-- token $ string "in"
-- ms <- many macroExpr
-- return ((name,e):ms) <|>
-- do {e <- token expr;return []}
expr
::
Parser
LamExpr
expr
=
do
{
x
<-
var
;
return
$
LamVar
x
}
<|>
expr
=
do
{
x
<-
var
;
return
$
LamVar
x
}
do
{
name
<-
macroName
;
return
$
LamMacro
name
}
<|>
<|>
do
{
name
<-
macroName
;
return
$
LamMacro
name
}
do
e1
<-
expr
<|>
do
e1
<-
expr
space
e2
<-
expr
return
$
LamApp
e1
e2
<|>
return
$
LamApp
e1
e2
do
char
'
\'
<|>
do
char
'
\
\
'
x
<-
var
symbol
"->"
e
<-
expr
return
$
LamAbs
x
e
<|>
return
$
LamAbs
x
e
do
char
'('
<|>
do
char
'('
e
<-
token
expr
char
')'
return
e
...
...
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