mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Add anamorphism example showing how to construct terms from strings
This commit is contained in:
parent
c093eb6838
commit
90ba2a73ab
@ -46,3 +46,15 @@ indexedTermCata :: [leaf] -> Term (Syntax leaf) (Record '[NewField, Range, Categ
|
||||
indexedTermCata childrenLeaves = cata algebra (indexedTerm childrenLeaves)
|
||||
where
|
||||
algebra term = cofree $ (NewField .: (headF term)) :< (tailF term)
|
||||
|
||||
{-
|
||||
Anamorphism -- construct a Term from a string
|
||||
|
||||
The example below shows how to build up a recursive Term structure from a string representation.
|
||||
-}
|
||||
stringToTermAna :: String -> Term (Syntax String) (Record '[Range, Category])
|
||||
stringToTermAna = ana coalgebra
|
||||
where
|
||||
coalgebra representation = case representation of
|
||||
"indexed" -> (Range 1 10 .: Category.MethodCall .: RNil) :< Indexed ["leaf"]
|
||||
_ -> (Range 1 10 .: Category.MethodCall .: RNil) :< Leaf representation
|
||||
|
Loading…
Reference in New Issue
Block a user