ChildsplayOSU / bogl

Haskell implementation of the BoGL language
https://bogl.engr.oregonstate.edu
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

Add in Tuple Projections #175

Closed montymxb closed 3 years ago

montymxb commented 3 years ago

Tuple selectors remain to be added into the language, per the official spec. This quickly describes the features, and some conditions we want to maintain when they are implemented.

Single Tuple Projection

Selects a single element from a tuple

t : Int
t = (5,4,3,2,1)#1    -- == 5

Tuple Projection

Selects a tuple of elements from a tuple.

t : Int
t = (5,4,3,2,1)#(1,3,5)  -- == (5,3,1)
montymxb commented 3 years ago

As an added note, tuple projections would likely need an additional entry on the tutorials to introduce them. Syntax highlighting on the front-end would need to be changed slightly to allow '#' to be marked as an operator.

alexgrejuc commented 3 years ago

I agree with most of the details except tuple projections should produce subsets of the original tuple.

I am guessing you wrote that because the spec has the line

The purpose of tuple projection is to extract a single value or a sub-tuple of values from a tuple

But honestly, that seems like an arbitrary restriction. If a user wants to expand a tuple, why stop them?

montymxb commented 3 years ago

I thought this as well at first, but I changed my mind after some reading.

It depends what theory you're basing it off of. My interpretation is that from projections in relational algebra, in which it can be thought of as reducing the original attributes and keeping the projected attributes. However, you are probably coming from projections as term constructors, and also maybe set theory? I think in that case the tuple projection here is akin to a composition of single tuple projections; which makes your case viable behavior. Either way, it's good we figure out exactly what the behavior should be for this. I'm okay with either approach, so long as our basis is clear.

Maybe Martin can weigh in with his thoughts.

MartinErwig commented 3 years ago

On Mar 19, 2021, at 4:18 PM, Benjamin Wilson Friedman @.***> wrote:

I thought this as well at first, but I changed my mind after some reading.

It depends what theory you're basing it off of. My interpretation is that from projections in relational algebra, in which it can be thought of as reducing the original attributes and keeping the projected attributes. However, you are probably coming from projections as term constructors, and also maybe set theory? I think in that case the tuple projection here is akin to a composition of single tuple projections; which makes your case viable behavior. Either way, it's good we figure out exactly what the behavior should be for this. I'm okay with either approach, so long as our basis is clear.

Maybe Martin can weigh in with his thoughts.

I think we should use the more general interpretation.

-- Martin

MartinErwig commented 3 years ago

Since BoGL is a teaching language, I think we should drop tuple selectors from the language.