Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
curry
curry-frontend
Commits
a4a66440
Commit
a4a66440
authored
Sep 24, 2012
by
Björn Peemöller
Browse files
First working version of fcase expressions
parent
a6d58b10
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Transformations/CurryToIL.lhs
View file @
a4a66440
...
...
@@ -288,7 +288,9 @@ uses flexible matching.
>
trEquation
vs
vs'
(
Equation
_
(
FunLhs
_
ts
)
rhs
)
=
do
>
-- construct renaming of variables inside constructor terms
>
let
patternRenaming
=
foldr2
bindRenameEnv
Map
.
empty
vs
ts
>
-- translate right-hand-side
>
rhs'
<-
trRhs
vs'
patternRenaming
rhs
>
-- convert patterns
>
return
(
zipWith
trPattern
vs
ts
,
rhs'
)
>
trEquation
_
_
_
>
=
internalError
"Translation of non-FunLhs euqation not defined"
...
...
@@ -350,9 +352,9 @@ instance, if one of the alternatives contains an \texttt{@}-pattern.
>
trExpr
(
v
:
vs
)
env
(
Case
r
ct
e
alts
)
=
do
>
-- the ident v is used for the case expression subject, as this could
>
-- be referenced in the case alternatives by a variable pattern
>
e'
<-
trExpr
vs
env
e
>
e'
<-
trExpr
vs
env
e
>
let
matcher
=
if
ct
==
Flex
then
flexMatch
else
rigidMatch
>
expr
<-
matcher
r
[
v
]
`
liftM
`
mapM
(
trAlt
vs
env
)
alts
>
expr
<-
matcher
r
[
v
]
`
liftM
`
mapM
(
trAlt
(
v
:
vs
)
env
)
alts
>
return
$
case
expr
of
>
IL
.
Case
r'
mode
(
IL
.
Variable
v'
)
alts'
>
-- subject is not referenced -> forget v and insert subject
...
...
@@ -425,16 +427,19 @@ hand sides of the remaining rules, eventually combining them using
Actually, the algorithm below combines the search for inductive and
demanded positions. The function \texttt{flexMatch} scans the argument
lists for the left-most demanded position. If this turns out to be
also an inductive position, the function \texttt{
m
atchInductive} is
also an inductive position, the function \texttt{
flexM
atchInductive} is
called in order to generate a \texttt{case} expression. Otherwise, the
function \texttt{optFlexMatch} is called that tries to find an inductive
position in the remaining arguments. If one is found,
\texttt{
m
atchInductive} is called, otherwise the function
\texttt{
flexM
atchInductive} is called, otherwise the function
\texttt{optFlexMatch} uses the demanded argument position found by
\texttt{
m
atch}.
\texttt{
flexM
atch}.
\begin{verbatim}
>
-- a 'Match' is a list of patterns and the respective expression
>
type
Match
=
([
NestedTerm
],
IL
.
Expression
)
>
-- a 'Match'' is a 'Match' with deferred patterns to be matched after
>
-- the next inductive position
>
type
Match'
=
([
NestedTerm
]
->
[
NestedTerm
],
[
NestedTerm
],
IL
.
Expression
)
>
flexMatch
::
SrcRef
-- source reference
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment