Hacker Timesnew | past | comments | ask | show | jobs | submit | ekipan's commentslogin

From the article:

    length = foldr (+) 0 . map (const 1)
    length2d = foldr (+) 0 . map length

    -- and the proposed syntax the author calls more readable:
    length = foldr((+), 0, $) . map(const(1), $)
    length2d = foldr((+), 0, $) . map(length, $)
But I don't understand. Why does the author think it's confusing to partially apply foldr and map but not (+), (.), const, and length? Applied consistently:

    length = (.)(foldr((+)($, $), 0, $), map(const(1, $), $), $)
    length2d = (.)(foldr((+)($, $), 0, $), map(length($), $), $)
And clearly no-one thinks this strawman is clearer. Further, it's impossible to make it 100% consistent: any function you write with polymorphic result could instantiate as a function needing more arguments. I think currying is the better default.


> Why does the author think it's confusing to partially apply foldr and map but not (+), (.), const, and length?

Neither of these functions is being partially applied in the code you cited. While the placeholder $ can be used to indicate all "free slots" of a function, you would only have to use it in partial applications of that function. (Analogous to how in mathematics the abstract index notation for tensors[0] is only really useful when you start contracting tensors, etc. Otherwise, the plain objects/tensors without indices are much easier to write & read.)

Specifically:

- (+) was already a function of two arguments, so usage of $ is unnecessary since (+)($, $) == (+). Similarly with the length function (a function of 1 argument): length($) == length.

- Function composition was being used as a binary operator between two functions. You just replaced the infix notation with prefix notation.

- I read const(1) as the function that maps everything to 1. I.e. `const` is a function of one argument x, which returns a function that always returns x. Once again, no need to indicate slots there.

[0]: See https://en.wikipedia.org/wiki/Abstract_index_notation and https://math.stackexchange.com/questions/455478/what-is-the-...


> - Function composition was being used as a binary operator between two functions. You just replaced the infix notation with prefix notation.

That's incorrect. Here's the definition of function compose:

  (f . g) x = f (g x)
So in `foldr (+) 0 . map (const 1)`, the author gives `f = foldr (+) 0` and `g = map (const 1)` but doesn't supply `x`. That's a partial application. Similarly for const:

  const x y = x
Even if I concede length and (+), these two are partially applied.

> you would only have to use it in partial applications of that function.

So why not const and (.)? If they're allowed to curry, why not foldr and map?


> So in `foldr (+) 0 . map (const 1)`, the author gives `f = foldr (+) 0` and `g = map (const 1)` but doesn't supply `x`. That's a partial application.

It's not, and the authors doesn't have to. Using your definitions, `f . g` is a function of a single free argument (whether you call it x or y or whatever). Partial application occurs when you want to fix some parameters but not all of them. In the present case, however, there is only one parameter (x) and it's not fixed, so there's no partial application to speak of and one can omit the parameter as usual.

Put differently: (.) is a binary operator on functions, and length = f . g from the OP is an equation of functions. You can certainly write it down pointwise, i.e. length(x) = (f . g)(x), but that doesn't tell you anything you didn't know already, and it is unrelated to the case of partial application that the author is discussing.


Yeah, this. Plus a mistake from the article:

  $ echo '*\n!.gitignore' > build/.gitignore
The \n won't be interpreted specially by echo unless it gets the -e option.

Personally if I need a build directory I just have it mkdir itself in my Makefile and rm -rf it in `make clean`. With the article's scheme this would cause `git status` noise that a `/build/` line in a root .gitignore wouldn't. I'm not really sure there's a good tradeoff there.


> The \n won't be interpreted specially by echo unless it gets the -e option.

Author's probably using Zsh, which interprets them by default.


If you want any kind of non-trivial formatting, use the printf command, not echo.


I forget the context but the other day I also learned about Snowflake IDs [1] that are apparently used by Twitter, Discord, Instagram, and Mastodon.

Timestamp + random seems like it could be a good tradeoff to reduce the ID sizes and still get reasonable characteristics, I'm surprised the article didn't explore there (but then again "timestamps" are a lot more nebulous at universal scale I suppose). Just spitballing here but I wonder if it would be worthwhile to reclaim ten bits of the Snowflake timestamp and use the low 32 bits for a random number. Four billion IDs for each second.

There's a Tom Scott video [2] that describes Youtube video IDs as 11-digit base-64 random numbers, but I don't see any official documentation about that. At the end he says how many IDs are available but I don't think he considers collisions via the birthday paradox.

[1]: https://en.wikipedia.org/wiki/Snowflake_ID

[2]: https://youtu.be/gocwRvLhDf8


Getting the entire universe to agree on a single clock for creating timestamps sounds absurdly difficult. Probably impossible?


"Agreement" of time is probably nonsense, yeah. I realized after posting so I edited in the parenthetical, but as [3] notes, locality probably makes this less of a real issue.

Apparently with the birthday paradox 32 bit random IDs only allow some tens of thousands per second before collision chance passes 50%. Maybe that's acceptable?

[3]: https://qht.co/item?id=47065241


You don't need the universe to agree. You need your ID system to agree within a reasonable margin of error.


The temperature of the cosmic microwave background can be used as a universal clock.


So can neutron star spin rates


Neutron star spins collectively can be used as a pretty accurate clock.


How? You are here on earth, looking at a neutron star. It pulses about N times a minute. I am 5ly away, looking at the same neutron star. Yes, i see the pulses happening at about N times per second, but the pulse delay you see at time T(a) is not the same pulse delay i see at time T(a), it would be another 5 years before i see the same pulse you saw.


> [1]: https://en.wikipedia.org/wiki/Snowflake_ID

Isn't this just the same scheme as version 1 UUID, except with half the bits? I guess they didn't want to dedicate 128 bits to their IDs.



That also looks like the widely used BSON ids, to anyone else interested


I think everyone agrees with the sentiment but practically speaking that ship sailed decades ago. Browsing the web without uBlock or similar is ill-advised.

Morbidly curious, I turned off my blockers and it's not as bad as I expected honestly. I can still read the article copy.


> And they keep forgetting the purpose of software is to serve users, not developers.

I don't have any horse in the game, but I do think Zig is interesting. This remark is funny to me because it's literally one of the tenets the Zig devs make decisions by!

https://ziglang.org/documentation/master/#Zen

> * Together we serve the users.


Oh, it's a list you can add to your uBO. I thought it was a descriptive headline: "(The) uBlock filter list (is going) to hide ..."

I only watch Youtube via browser now for both adblocking and my own custom userscripts, both on my laptop and my phone. A couple creators I watch mostly do shorts so I tolerate them but I wrote a userscript that changes all /shorts/<videoid> URLs into normal /watch?v=<videoid> to lessen the temptation to doomscroll.


It seems to me that AI is mostly optimized for tricking suits into thinking they don't need people to do actual work. If I hear "you're absolutely right!" one more time my eyes might roll all the way back into my head.

Still, even though they suck at specific artifacts or copy, I've had success asking an LLM to poke for holes in my documentation. Things that need concrete examples, knowledge assumptions I didn't realize I was making, that sort of thing.

Sweet Gameboy shader!


You're absolutely right! (sorry, I couldn't resist)


I actually have the below clashes function in my bashrc to detect overloaded names, and a few compgen aliases for sorted formatted command lists. Clashes takes a few seconds to chew through the 3000ish commands on my Steam Deck.

I also discovered the comma thing myself, and use it for `xdg-open <web-search-url>` aliases, i.e. `,aw xdg` searches archwiki for "xdg", since the SteamOS on this thing doesn't have manpages.

  alias words='iftty xargs'   # join by spaces
  alias c='compgen -c | sort -u | words' # eg: c | grep ^k | chop
  # ... a for aliases, f for functions etc ...
  alias man='g !archman'      # https://man.archlinux.org
  alias ,aw='g !aw'           # https://wiki.archlinux.org
  alias ,mdn='g !mdn'         # https://developer.mozilla.org
  alias ,nix='g !nixpkgs'     # https://search.nixos.org
  # ... a dozen others ...

  g() { local IFS=+; xdg-open "https://ddg.gg/?q=$*"; }
  iftty() { if [ -t 1 ]; then "$@"; else cat; fi; }

  chop() { # [TABS] [STARTCOL] [CUTOPTS..] # eg. ls ~/.co* | chop
    set -- "${1:-2}" "${2:-1}" "${@:3}"
    cut -c "$2"-$(($2+8*$1-2)) "${@:3}" | column #| less
  }

  clashes() { # [CMDS..] # print overloads eg: clashes $(c)
    (($#)) || set -- $(compgen -A alias -A function)
    local ty cmd; for cmd; do ty=($(type -at "$cmd"))
    ((${#ty[@]}>1)) && echo -n "$cmd "; done; echo
  }


(Edit: in the old post title:) "everything is a value" is not very informative. That's true of most languages nowadays. Maybe "exclusively call-by-value" or "without reference types."

I've only read the first couple paragraphs so far but the idea reminds me of a shareware language I tinkered with years ago in my youth, though I never wrote anything of substance: Euphoria (though nowadays it looks like there's an OpenEuphoria). It had only two fundamental types. (1) The atom: a possibly floating point number, and (2) the sequence: a list of zero or more atoms and sequences. Strings in particular are just sequences of codepoint atoms.

It had a notion of "type"s which were functions that returned a boolean 1 only if given a valid value for the type being defined. I presume it used byte packing and copy-on-write or whatever for its speed boasts.

https://openeuphoria.org/ - https://rapideuphoria.com/


> It had a notion of "type"s which were functions that returned a boolean 1 only if given a valid value for the type being defined.

I've got a hobby language that combines this with compile time code execution to get static typing - or I should say that's the plan, it's really just a tokenizer and half of a parser at the moment - I should get back to it.

The cool side effect of this is that properly validating dynamic values at runtime is just as ergonomic as casting - you just call the type function on the value at runtime.


Thanks, I updated the post title based on this and another comment. Thanks for the pointer to Euphoria too, looks like an interesting language with a lot of similar ideas.


Strange. Middle-clicking the link opens a HackerNews frontpage, but copypasting into a new tab shows the article. Presumably the server shoos away referer links? To reduce load maybe somehow? Or maybe something's weird in my own configuration idk.


They explicitly check if the referrer is hackernews and do that.


I had the same issue as you. Had to copy and paste the link.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: