yurtsiv / mooncake

🌜 A functional, dynamic programming language
MIT License
13 stars 4 forks source link

Enhance `==` operator to support more types #2

Open yurtsiv opened 3 years ago

yurtsiv commented 3 years ago

Currently == only works on integers. We need to implement it for each existing type and it should always compare by value.

Semantics

# True

1 == 1
"" == ""
"Hi" == "Hi"
[] == []
[1,2,3] == [1,2,3]
True == True

# False

1 == 0
" " == ""
"Hi" == "HI"
True == False

# Invalid (can't compare functions and can only compare values of the same type)

let func = (x) do
  x
end

func == func
[1, 2, func] == [1, 2, func]
1 == ""
1 == []
1 == True
"Hi" == ["H", "i"]
# etc...

EDIT:

Since /= is already implemented, we should make it work too

siddhantrao23 commented 3 years ago

Hey! I'd love to work on this. I went through the code base and the majority of changes should be made in interpreter/eval.hs, any further directions you could provide would be really helpful.

yurtsiv commented 3 years ago

Hi @siddhantrao23,

Yes, you're right. The exact place is where -- TODO: compare all primitive types is located.

I'd recommend adding tests first (test/Interpreter/EvalSpec.hs) and then gradually implementing the functionality.

stack test --file-watch is really handy in this case

Thank you!

yurtsiv commented 3 years ago

@siddhantrao23 Description is updated slightly

siddhantrao23 commented 3 years ago

Thanks! I'll start working on it now

siddhantrao23 commented 3 years ago

hey @yurtsiv My exams came up so I didn't get to work on this! If there are others, do go ahead. I will contribute after my exams.

yurtsiv commented 3 years ago

@siddhantrao23 Hi! No problem :slightly_smiling_face: