Haskell-style pattern matching implementation with type checking

I am working on a project to recreate some of the Haskell features in Clojure. I managed to implement an output like Hindley-Milner, and now I'm trying to introduce a pattern matching syntax using a macro. My goal is for the macro to emit valid Clojure code first and then enter validation of that code, but I find it difficult. Since I'm new to Haskell and static typing in general, I'm not sure if there is a way to do this that I don't see, or is it just not possible.

I am trying to execute the Luc Maranget algorithm , at least the naive version at the moment. I understand that you take a vector of values ​​(or "occurrences" at compile time) and treat it like a stack. After grouping the pattern strings with the constructors of the first column, you will find a group of patterns corresponding to the constructor of the first value in the vector. If the vector (v1 ... vn), a v1- c(a1 ... ak), where cis the constructor, and a1 ... akare the constructor arguments, then you discard the constructor cand combine the arguments with the vector, creating a new vector (a1 ... ak v2 ... vn)and recursively execute the algorithm.

My question is, how do you represent such a vector or stack in a way that can be verified? Again, my goal is for the Clojure macro to produce code that is ready to process runtime values, but also ready to type check at compile time. I could introduce an intermediate step in which the first macro emits a code that can be checked by type, but is itself a macro, and then the second macro emits a code that will actually be executed. But even if this works, it is less satisfactory, since it assumes that I could not have completed such a task in Haskell. Did I miss something?

- EDIT -

, - , , . , , , , , . , , , , Haskell. .

+4

Source: https://habr.com/ru/post/1680007/


All Articles