Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
pseudorandom name
May 6, 2007

Notorious b.s.d. posted:

iostreams has a lot of problems but the builder pattern isn't the root of them

I too like text output systems that cannot be localized.

Adbot
ADBOT LOVES YOU

Notorious b.s.d.
Jan 25, 2003

by Reene

pseudorandom name posted:

I too like text output systems that cannot be localized.

there are plenty of ways to build a printf replacement that doesn't involve a second little macro language, unchecked by your compiler, inside string literals

but yeah a builder with inline strings has the notable downside of not easily changing the location of substitutions

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Notorious b.s.d. posted:

let me turn this around for you.

leaving the loop implementation exactly the same, do you consider this an improvement?

code:
(#%%~ ^@!? 5 ^. x = 0 <<.= y ^. y = 1 <<.= (+ x y) %@~ y)
each of these is a real operator from that haskell library.

did moving to arbitrary non-words improve or hurt the readability of a perverse mis-use of a macro that neither of us likes?

Since I've never really written a line of Haskell here, is that how those operators are usually used?

I thought this was more of a domain-specific thing where you have:

x = (y #%%~ z)

funroll loops
Feb 6, 2007
CAPSISSTUCK
i mean idk since i dont use haskell at all, but maybe that's not so bad? at least the goofy operators are compositions of regular haskell operators, right? it seems like if you were comfortable with the regular syntax of haskell then you could piece together what the operators meant. this is actually why long names are good, you piece together the meanings of the whole from each individual word. often times you are trading inscrutable operators with jargon. the same with the loop macro or whatever. you derive the meaning from experience and context just like with anything else.

once again, maybe not totally applicable, but compare it to the math analogy. if you blew up all of your variables to long names you would have pretty much incomprehensible and unfixable garbage for any but the most basic of problems. brevity can improve readability. it isn't a one way street.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Notorious b.s.d. posted:

there are plenty of ways to build a printf replacement that doesn't involve a second little macro language, unchecked by your compiler, inside string literals

but yeah a builder with inline strings has the notable downside of not easily changing the location of substitutions

Just curious, do you have any ideas for a localizable printf replacement?

gonadic io
Feb 16, 2011

>>=

Suspicious Dish posted:

Since I've never really written a line of Haskell here, is that how those operators are usually used?

I thought this was more of a domain-specific thing where you have:

x = (y #%%~ z)

AlsoD posted:

let's look at some real code, some of the worst examples from my game (well i call it that, it's barely at the stage where it's interactive)

code:
actions :: Float -> [(Key, State -> State)]
actions dt =
    [ (Char 'w', viewPort.vpTranslate._2 -~ 5  *dt)
    , (Char 's', viewPort.vpTranslate._2 +~ 5  *dt)
    , (Char 'a', viewPort.vpTranslate._1 +~ 5  *dt)
    , (Char 'd', viewPort.vpTranslate._1 -~ 5  *dt)
    , (Char '-', viewPort.vpScale        *~ 1-1*dt)
    , (Char '=', viewPort.vpScale        *~ 1+1*dt)
    , (Char 'r', const initialState)
    , (MouseButton LeftButton , setSelection      )
    , (MouseButton RightButton, moveSelectedPlayer)
    ]
"viewPort.vpTranslate._2" delves into a structure and then i modify its value using +,- or *. simple.

code:
handleInput :: Event -> State -> State
handleInput (EventKey k keyState _ _) s = s &
     keysDown . contains k .~ (keyState == Down)
in the field keysDown which is a set that contains the element k if the keyState is down

code:
handleInput (EventMotion xy) s = s &
    mouseOver ?~ invertViewPort (_viewPort s) xy
?~ is like .~ for a Maybe field i.e. (l ?~ x) is (l .~ (Just x))

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
It seems I missed that post before. Thanks for the quote, and thanks for explaining! I understand better now.

Notorious b.s.d.
Jan 25, 2003

by Reene

Suspicious Dish posted:

Just curious, do you have any ideas for a localizable printf replacement?

idk design is not my strong suit.

maybe something with placeholders ala printf, but no type impositions? all arguments must be a string, with processing finished before being passed on.

there has got to be a better way to do this, to enable more checking by the compiler (e.g. number of placeholders)

funroll loops
Feb 6, 2007
CAPSISSTUCK
bad operator usage is for instance the example of the minus sign with strings, god drat thats loving dumb. without an example you have no idea what it means and the actual subtractions could potentially give you errors, gross. if you're going to use math operators you better be sure it actually works like math.

Notorious b.s.d.
Jan 25, 2003

by Reene

funroll loops posted:

i mean idk since i dont use haskell at all, but maybe that's not so bad? at least the goofy operators are compositions of regular haskell operators, right? it seems like if you were comfortable with the regular syntax of haskell then you could piece together what the operators meant. this is actually why long names are good, you piece together the meanings of the whole from each individual word. often times you are trading inscrutable operators with jargon. the same with the loop macro or whatever. you derive the meaning from experience and context just like with anything else.

Notorious b.s.d. posted:

so because the rest of haskell is loving terrible, the abortions in the lens library are supposed to get a free pass?

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

coffeetable posted:

mathematical ideas are best communicated with prose. the notation's just there to a) provide rigour where plain english can't and b) so the reader doesn't have to invent their own notation when they themselves want to manipulate the ideas at hand.

this is entirely true but it's far more efficient to have symbols.

it has diminishing returns so poo poo like "=" is a-ok but im doubtful that %%@= is actually useful to anyone

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Notorious b.s.d. posted:

there are plenty of ways to build a printf replacement that doesn't involve a second little macro language, unchecked by your compiler, inside string literals

but yeah a builder with inline strings has the notable downside of not easily changing the location of substitutions

dependent types now!!!!

double sulk
Jul 2, 2010

haskell is useless

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

bsd stymie strikes again!

show me on this code where the bad language touched you

meanwhile, the cool kids will be riding through the fields on the horse of true mathematics :)

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

double sulk posted:

haskell is useless

:ironicat:

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

double sulk posted:

haskell is useless
were you sulk 1.0 or did toby punish someone else with the mantle

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

double sulk posted:

haskell is useless

dont sign you are posts!!!!!

funroll loops
Feb 6, 2007
CAPSISSTUCK

i mean if you are too stupid to take a tiny bit of time to understand what operators that work consistently mean then idk what to tell you. it isn't always a bad idea to collapse extremely commonly used and generic things into smaller symbols because the brevity can make things clearer. see: math

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
simon peyton jones said it himself https://www.youtube.com/watch?v=iSmkqocn0oQ

b0lt
Apr 29, 2005

Notorious b.s.d. posted:

a second little macro language, unchecked by your compiler

maybe you should get a better compiler :smug:

vOv
Feb 8, 2014

why are so many people unable to distinguish 'operator overloading' from 'defining your own infix operators'

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

vOv posted:

why are so many people unable to distinguish 'operator overloading' from 'defining your own infix operators'

(vOv)

funroll loops
Feb 6, 2007
CAPSISSTUCK

vOv posted:

why are so many people unable to distinguish 'operator overloading' from 'defining your own infix operators'

the intent is nearly the same, you just carry less baggage when you don't use the regular math ones

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

funroll loops posted:

the intent is nearly the same, you just carry less baggage when you don't use the regular math ones

the baggage is good though. if i overload (+) on my vector type, it is patently obvious to anyone reading what (u + v) is computing. conversely, the first seventeen times they encounter (u #!% v) they're going to have to toddle off to the documentation

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
ofc, if you can labour under the assumption that anyone reading your code is already familiar with (#!%) and its effect on vectors, then it's absolutely fine to use (#!%). if lenses became ubiquitous throughout the programming world, it'd be fine to use them because as alsod says, there is a method in their madness and it doesn't take long to learn how to deduce what they do.

but very few people are familiar with lenses and that's not changing any time soon so~

Deus Rex
Mar 5, 2005

coffeetable posted:

the baggage is good though. if i overload (+) on my vector type, it is patently obvious to anyone reading what (u + v) is computing. conversely, the first seventeen times they encounter (u #!% v) they're going to have to toddle off to the documentation

Oh, and what does the overloaded (*) do on your vector type?

motedek
Oct 9, 2012
the lens operators ain't great but they're pretty much required knowledge to get a job in software these days

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Deus Rex posted:

Oh, and what does the overloaded (*) do on your vector type?
you don't overload (*) on your vector type because it doesn't have a standard analogous operation in the body of knowledge we assume any reader shares.

double*vector, fine
vector*double, fine
vector.vector, fine

(guessing this is what you were saying)

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Deus Rex posted:

Oh, and what does the overloaded (*) do on your vector type?

crossproduct b/c i make my vectors an applicative functor so i can use element wise poo poo

but only for 3d vectors (and 7d but lmao)

and my inner product is *.

and my outer product is (,)

funroll loops
Feb 6, 2007
CAPSISSTUCK

coffeetable posted:

the baggage is good though. if i overload (+) on my vector type, it is patently obvious to anyone reading what (u + v) is computing. conversely, the first seventeen times they encounter (u #!% v) they're going to have to toddle off to the documentation

it's only good when used in that way, rather than retards overloading the - operator on strings or whatever.

quote:

ofc, if you can labour under the assumption that anyone reading your code is already familiar with (#!%) and its effect on vectors, then it's absolutely fine to use (#!%). if lenses became ubiquitous throughout the programming world, it'd be fine to use them because as alsod says, there is a method in their madness and it doesn't take long to learn how to deduce what they do.

but very few people are familiar with lenses and that's not changing any time soon so~

like i said before i dont really know haskell but doesn't lenses just let you combo a bunch of poo poo together that is usually there to begin with? even if not it doesn't seem like it would take a gargantuan amount of effort to understand what each operator does and then how they get linked together. context etc.


i mean you can just go and use the most popular things, thats fine, but sometimes you might miss out on better alternatives. it's basically shaggaring to say that the most popular is the objective best because its the most popular.

FamDav
Mar 29, 2008

motedek posted:

the lens operators ain't great but they're pretty much required knowledge to get a job in software these days

i always want to hear from people doing haskell work that is

not for a bank and
not an otherwise one off project within a company

gonadic io
Feb 16, 2011

>>=
and on the topic of punctuation let's talk about list comprehensions

haskell: [(x+y)^2 | x <- [0..10], y <- [0..10], even x, odd y]
python: [pow (x+y,2) for x in range(0,11) for y in range (0,11) if x&2 if not (y&2)]

i know which one i prefer.

what does it look like in c#/linq btw?

gonadic io fucked around with this message at 02:36 on Feb 9, 2014

FamDav
Mar 29, 2008
im p sure its like

from x in Listwhatever
from y in OtherListWhatever
select (x+y)^2
where x%2
where !(y%2)

FamDav
Mar 29, 2008
never used c# tho

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

AlsoD posted:

and on the topic of punctuation let's talk about list comprehensions

haskell: [(x+y)^2 | x <- [0..10], y <- [0..10], even x, odd y]
python: [(x+y)^2 for x in range(11) for y in range (11) if x&2 if not (y&2)]

how does LINQ do it?

iirc, either

from x in Enumerable.Range(0, 10)
from y in Enumerable.Range(0, 10)
where x%2 == 0
where y%2 == 1
select Math.Pow(x+y, 2)

or

from x in Enumerable.Range(0, 10)
join y in Enumerable.Range(0, 10) on x%2 not equals y%2
select Math.Pow(x+y, 2)

or

Enumerable.Range(0, 10).Join(Enumerable.Range(0, 10), x => x%2 - 0, y => y%2 + 1, (x, y) => Math.Pow(x+y, 2))

personally id go w/ the first, but with helper functions for even, odd and square. the fact C# doesn't have an integer power operator still irks me

coffeetable fucked around with this message at 02:41 on Feb 9, 2014

pseudorandom name
May 6, 2007

Deus Rex posted:

Oh, and what does the overloaded (*) do on your vector type?

nothing, because you've overloaded ⨯ and ∙ instead

gonadic io
Feb 16, 2011

>>=

pseudorandom name posted:

nothing, because you've overloaded ⨯ and ∙ instead

oh god I wish I had (∘) instead of (.) in haskell. we've had the unicode sytax discussion before though

Deus Rex
Mar 5, 2005

AlsoD posted:

oh god I wish I had (∘) instead of (.) in haskell. we've had the unicode sytax discussion before though

oh, but you can http://hackage.haskell.org/package/base-unicode-symbols-0.2.2.4/docs/Prelude-Unicode.html

gonadic io
Feb 16, 2011

>>=

AlsoD posted:

we've had the unicode sytax discussion before though

it's more of a "recognise it's probably a bad idea" thing

e: poo poo imagine how fun lens would be with unicode operators
or classy-prelude

or just being able to use ⅓ and such

gonadic io fucked around with this message at 03:22 on Feb 9, 2014

Adbot
ADBOT LOVES YOU

Deus Rex
Mar 5, 2005

Can we talk for a second about editor-agnostic "IDE" tooling, by which I mean packages like ENSIME, nREPL, TSS or Eclim that analyze your source and provide a channel for communicating autocompletion, type information, on-the-fly evaluation, searching, validation and other IDE niceties with the editor of your choice. Why did it take until pretty recently (the Eclim project started in 2005) for this kind of separation of editor + IDE features to come around? Why was/is everyone re-inventing these wheels for every which Emacs/Vim/Sublime Text/loving whatever?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply