Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can create an interpreter in the finally tagless style:

https://okmij.org/ftp/tagless-final/

This embeds the target language as combinators in a host language, so you can construct and evaluate programs.



I have not heard of tagless final style interpreter before and that seems really neat. However, based on the link it seems that tagless final interpreter uses a strong type language like Haskell or ML so I don’t know how well it would translate to Javascript, which is what the GP comment said they were using.


I've done them in C# with slightly less safety.

https://higherlogics.blogspot.com/search/label/tagless%20int...

The style of the construction is what matters most. If you're using JS then you're already giving up types, but the higher order abstract syntax is what lets you embed and play with language semantics.


I think I may have misunderstood what your original comment was referring to. Were you saying that one doesn’t need a parser to make a working interpreter? I want to make sure that I understand the context of your comments because looking at the post you linked where you did this in C# you show you are using a recursive descent parser. It was when I saw the parser that I realized I could be way off base on what I was thinking you were talking about.


Yes, it doesn't need a parser. I didn't link to one post, it's a tag that links a series of posts discussing tagless interpreters. You can use the interpreter in the first post directly without the parser as well, it's a separate component. IQueryLanguage<T> is the interpreter definition.


I should note that the other posts go into more of the theory and background of final tagless encodings, including links to Oleg's site who has done a lot of work on them. They are a very flexible for implementing embedded languages.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: