Giter Club home page Giter Club logo

Comments (5)

marzipankaiser avatar marzipankaiser commented on July 20, 2024 2

Minor nitpick: We might want to call them prefixNeg and prefixNot...

from effekt.

dvdvgt avatar dvdvgt commented on July 20, 2024 1

-(x + y) is perfectly valid and very commonly used mathematically expression. I have never seen someone write 0 - (x + y) instead. Do you have an example where this appears as a code smell?

For example, the normal distribution is defined as N(x; mu, sigma) ~ e^(-((mu - sigma)^2 / (2 * sigma^2)). I have never seen it given as N(x; mu, sigma) ~ e^(0 - ((mu - sigma)^2 / (2 * sigma^2)) instead. If someone wanted to implement this in Effekt, I would imagine the normal user would like to stick as close as possible to common mathematical notations and not having to think about how to desugar it.

Edit: A perhaps easier example: negative fractions. It is more convenient and more common to write - (1 / 2) instead of 0 - (1 / 2).

from effekt.

dvdvgt avatar dvdvgt commented on July 20, 2024

Yes, right. That's a typo... edited

from effekt.

b-studios avatar b-studios commented on July 20, 2024

Why would we want to write -(1+2)? For prefixNot I can understand it, but -(1+2) is a smell in my opinion. Is there a usecase where you think this is better than 0 - (1 + 2)?

Another prefix operator that could be useful is bitwise negation ~x where typically we wouldn't desugar it into "subtraction".

from effekt.

b-studios avatar b-studios commented on July 20, 2024

Ok, here are two points to address

  1. spaces: a lot of Effekt code is written by students (in theses, etc.). Since we do not have a nice formatter, they end up using the most creative way to use whitespaces. I would be very happy if 1-x would just fail and force them to write 1 - x. Ideally, also 1- x should fail.

  2. - as unary operator. This is mostly personal taste. I have a dislike for prefix and postfix operators. I almost always write x = x + 1 instead of x++. I am also happy to write 0 - x instead of x, like here:

def neg(n: Double): Double =
0.0 - n

Actually, I typically write -1 * ... instead of 0 - ...and I think it works pretty well in your example as well.

The normal distribution is a bit of a red hering, since you use other operators that typically also don't exist in PLs (like ^ for exponentiation).

from effekt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.