sifive / wake

The SiFive wake build tool
Other
86 stars 28 forks source link

Intrinsic is(Data)(Type) API for `data` #843

Open jinrudals opened 2 years ago

jinrudals commented 2 years ago

Given the following case,

data A = 
  B
  C (some : SomeType)
def mylist = (B, C 3, B, C 4, Nil)

to filter mylist with type C B only, we do as following

def isB : A => Boolean = match _
  B = True
  _ = False
def isC : A => Boolean = match _
  C _   = True
  _     = False

def mylist = (B, C 3, B, C 4, Nil)
def b_only = mylist | filter isB
def c_only = mylist | filter isC

This is totally fine when data A has few types.

However, time to time we may add new case of data A, and every time we need to define new isD, isE.

How about adding new API to check type of data instead?

terpstra commented 2 years ago

Yeah, analogous to how tuple has get/set/edit methods, I have considered adding automatic helper methods along the lines of getAC: A => Option (some: SomeType). I just haven't decided on what form these should take. Furthermore, I remain hopeful that we can get field accessor methods like obj.field to work in the future, and I'd like these to line up nicely, whenever that happens.

jinrudals commented 2 years ago

Do you mean tuple instance's filed ? Or do you mean field of each data type? For instance C.some