3

I am currently writing a programming language in Haskell. This programming language is similar to Factor, being a concatenative stack-based language. However, after getting quite far, I hit a brick wall: I have a Data.Map of type:

Map.Map String ([YodaVal] -> YodaVal, Int) But I need the functions stored in the map to take the map as a parameter, so I can preserve environment when recursing, and also to possibly allow recursive function definitions, and recursive definitions of Haskell --> Yoda functions. However, the type would then look like:

type Env = Map.Map String ([YodaVal] -> Env -> [YodaVal] -> YodaVal, Int) Which of course expands to:

Map.Map String ([YodaVal] -> Map.Map String ... -> [YodaVal] -> YodaVal, Int)

psmears
  • 26,070
  • 4
  • 40
  • 48
Alexis Dumas
  • 1,299
  • 11
  • 30
  • 1
    Can you give an example of what you are trying to do? - I think there is a simpler solution. – ErikR Sep 01 '15 at 15:30
  • Here is the conventional way of implementing an interpreter in Haskell: http://stackoverflow.com/questions/16970431/implementing-a-language-interpreter-in-haskell See the "Evaluating Expressions" section. How about doing it that way? – ErikR Sep 01 '15 at 15:38
  • @user5402, yeah, i was thinking there must be. I'm sorry if my question was not clear, but the above type is the type of my variable envirnoment. I want to be able to pass the current variable environment into the functions in that variable envirnoment. – Alexis Dumas Sep 01 '15 at 17:04

1 Answers1

6

You can describe infinite types with a newtype:

newtype Env = Env {getEnv :: Map String ([Val] -> Env -> [Val] -> Val, Int))}

This will typecheck, and the runtime representation will be as if there were no wrapper.

AJF
  • 11,767
  • 2
  • 37
  • 64