Representing a type system in Haskell

Hello everyone, I'm working on a game engine in Haskell. The thing is, while I want to write the architecture in Haskell, I'm thinking of using something else as the actual scripting language. Long story short, how would I represent a type system in Haskell? I've gotten _something_ together that works a bit like this: ``` data Type = -- ...all possible types data Value = -- ...all possible types again data TypedValue = TypedValye Type Value ``` But I'm concerned if this is the ideal way of doing things, particularly when I get to complex types like structs or tagged unions. Any help would be appreciated. Sent from Proton Mail mobile

So to make sure I'm understanding correctly, you want to create your own statically typed scripting language for your game engine? Implementing your own statically-typed language is definitely a fun and worthwhile learning experience. You might find helpful the notes from my programming languages course, which is taught in Haskell: https://hendrix-cs.github.io/csci360/ Having `Type` and `Value` ADTs to represent types and values makes sense. They often do correspond closely since there is often a canonical kind of value for each type, but they are not necessarily exactly the same. You didn't mention an ADT for expressions/terms, i.e. syntax. Typically you will parse concrete syntax to produce a Term, and then you will typecheck a Term to make sure it has a valid Type. Then you can interpret the Term to produce a Value. I am not sure what the point of TypedValue is. Typically, once you are finished with typechecking, you no longer need to keep track of types while interpreting. -Brent On Mon, Jul 10, 2023 at 7:36 AM Talha Qamar via Haskell-Cafe < haskell-cafe@haskell.org> wrote:
Hello everyone, I'm working on a game engine in Haskell. The thing is, while I want to write the architecture in Haskell, I'm thinking of using something else as the actual scripting language.
Long story short, how would I represent a type system in Haskell? I've gotten _something_ together that works a bit like this:
``` data Type = -- ...all possible types data Value = -- ...all possible types again data TypedValue = TypedValye Type Value ``` But I'm concerned if this is the ideal way of doing things, particularly when I get to complex types like structs or tagged unions.
Any help would be appreciated.
Sent from Proton Mail mobile
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

I feel like I should elaborate on my usecase a little bit more. The arcitecture of my game engine is that there's a hypothetical giant struct that contains all of your game data, and then there's a giant pure function that takes an input state and the previous game state, and gives you the game state for the new frame. The problem is that writing a big function like that is a bit unwieldly, so I had the idea of separating each part out into a tiny script containing a pure function. My initial idea was that if I could strip out the io and os modules from the environment, each lua module (file) would be considered pure as a whole. So this type system was designed such that I could: Get a value of a type -> Convert it to lua types -> call lua code with it -> Convert into my type system -> Type check the result I don't know if I needed the TypedValue; but I felt it was convenient for a value to carry around it's type for some reason, my (in foresight flawed) vision was that lua code would call into haskell code, and I would keep on type checking in the interim, but I now realize that I don't need to do that if I'm checking at the end anyways. Now that you mention it, implementing my own statically typed language would probably be better than trying to rig a strict type system on a traditionally dynamically typed language. I have to think about this for a little bit. Thank you for the notes, I'll be looking them over. -------- Original Message -------- On Jul 10, 2023, 7:01 PM, Brent Yorgey wrote:
So to make sure I'm understanding correctly, you want to create your own statically typed scripting language for your game engine? Implementing your own statically-typed language is definitely a fun and worthwhile learning experience. You might find helpful the notes from my programming languages course, which is taught in Haskell: https://hendrix-cs.github.io/csci360/
Having `Type` and `Value` ADTs to represent types and values makes sense. They often do correspond closely since there is often a canonical kind of value for each type, but they are not necessarily exactly the same.
You didn't mention an ADT for expressions/terms, i.e. syntax. Typically you will parse concrete syntax to produce a Term, and then you will typecheck a Term to make sure it has a valid Type. Then you can interpret the Term to produce a Value.
I am not sure what the point of TypedValue is. Typically, once you are finished with typechecking, you no longer need to keep track of types while interpreting.
-Brent
On Mon, Jul 10, 2023 at 7:36 AM Talha Qamar via Haskell-Cafe
wrote: Hello everyone, I'm working on a game engine in Haskell. The thing is, while I want to write the architecture in Haskell, I'm thinking of using something else as the actual scripting language.
Long story short, how would I represent a type system in Haskell? I've gotten _something_ together that works a bit like this:
``` data Type = -- ...all possible types data Value = -- ...all possible types again data TypedValue = TypedValye Type Value ``` But I'm concerned if this is the ideal way of doing things, particularly when I get to complex types like structs or tagged unions.
Any help would be appreciated.
Sent from Proton Mail mobile
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (2)
-
Brent Yorgey
-
Talha Qamar