This repository has been archived by the owner on May 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Embedded terms #174
Merged
Merged
Embedded terms #174
Changes from 19 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
4af80b1
Add an `Embedded` case to `Expression`.
robrix 701df01
Check that the annotations on embedded terms are types.
robrix 1f2978e
Add a convenience constructor for Embedded Terms.
robrix b6c87a8
Add a convenience constructor for Embedded Terms of Embedded types.
robrix 6937007
Add a convenience constructor for Embedded types.
robrix 1ecc07a
Use the Embedded type constructor in the Embedded value constructor.
robrix bf2db11
Stub in a String module.
robrix d3ee938
Embed a String type.
robrix 6a35963
Add the String module to the directory.
robrix c3f7d8d
Embed a Character type.
robrix 89e9c0f
Add some references to List module terms.
robrix f15503b
Write a function to construct a List Character from a String.
robrix 7bbd346
Add a binding toList : String → List Character.
robrix ccfd1db
Single-quote embedded values.
robrix 3e03987
Judge any two Embedded values with the same dynamic & annotated types…
robrix a6c161a
Use a single code path for Embedded Term construction.
robrix 59f2a80
Generalize Embedded Term construction.
robrix 216e058
Add an Embedded constructor taking an equality function.
robrix 299a863
Embed an equality function alongside the value.
robrix 7619047
Spacing.
robrix 2904ad9
Use guard clauses to tidy up evaluation.
robrix 61b0a1e
Log both the original term and its evaluated form in illegal applicat…
robrix 0d46ab8
Rephrase Application evaluation as a nested switch.
robrix aa927f7
Evaluate embedded functions of type `Term throws -> Term`.
robrix 789305f
Add a Term constructor embedding named evaluator functions.
robrix 33e36a5
Evaluation expects evaluator terms to be named.
robrix 5444d4b
Correct the construction of Embedded types to not use the Optional ==…
robrix ff5bdbe
Add a convenience to embed characters with the defined type.
robrix 808e1dc
A more concise `toTerm` function.
robrix 67dc771
Add an Embedded Term constructor which automatically unwraps host val…
robrix 6fc6c5d
Let the type remain tacit.
robrix 1fd3c40
Define toList by embedding.
robrix 57b6b7e
Test that `toList` constructs strings correctly.
robrix c112963
Stub in a `fromList` definition.
robrix cf26156
Move `embedCharacter` into a private global.
robrix 4a90066
We need to quote the type name here.
robrix 4b2bb29
We don’t need to namespace here.
robrix edb766c
Just quote the type name directly.
robrix 8d9144d
Normalize the error against the others.
robrix a1927d1
Test the conversion of empty lists to strings.
robrix 6b722db
Test the operation of `List` values as eliminators.
robrix 975a9a7
Rename `a` to `aʹ`.
robrix 2c40b73
Substitution does not replace shadowed variables.
robrix 1e8ec9a
Correct which value we log for illegal applications.
robrix 70d1578
Remove an extra lambda in `Sigma.second`.
robrix bb2b0e9
Carry the `visited` set into recursive invocations correctly.
robrix aed04f2
Definitional equality does not use the visited set.
robrix cad85c3
Weak head normal form does not use the visited set.
robrix 4bc82fb
Define `fromList` via a helper function, `combine`.
robrix 109c25f
Test `fromList` against a single-character list.
robrix 295d5e8
Test `fromList` against a multiple-character list.
robrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ extension Module { | |
sigma, | ||
vector, | ||
finiteSet, | ||
string, | ||
].map { ($0.name, $0) }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright © 2015 Rob Rix. All rights reserved. | ||
|
||
extension Module { | ||
public static var string: Module { | ||
let List: Term = "List" | ||
let cons: Term = "cons" | ||
let `nil`: Term = "nil" | ||
|
||
let String = Declaration("String", | ||
type: .Type, | ||
value: .Embedded(Swift.String.self)) | ||
|
||
let Character = Declaration("Character", | ||
type: .Type, | ||
value: .Embedded(Swift.Character.self)) | ||
|
||
func toTerm(characters: Swift.String.CharacterView) -> Term { | ||
switch characters.first { | ||
case let .Some(c): | ||
return cons[Character.ref, .Embedded(c), toTerm(characters.dropFirst())] | ||
default: | ||
return `nil`[Character.ref] | ||
} | ||
} | ||
|
||
let toList = Declaration("toList", | ||
type: String.ref --> List[Character.ref], | ||
value: () => { (string: Term) -> Term in | ||
guard case let .Embedded(value as Swift.String, _, _) = string.out else { return ("toList" as Term)[string] } | ||
return toTerm(value.characters) | ||
}) | ||
|
||
return Module("String", [ list ], [ String, Character, toList ]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect.
We evaluate this function when the value term is constructed, not when the defined
toList
term is evaluated. Therefore, it always fails theguard
clause, produces itself in neutral form, and diverges during evaluation.