HackerTrans
TopNewTrendsCommentsPastAskShowJobs

_rend

no profile record

Submissions

Trump says he'll raise tariffs to 15 percent after Supreme Court ruling

apnews.com
17 points·by _rend·5 माह पहले·9 comments

comments

_rend
·2 माह पहले·discuss
To expand a bit, too, on how these definitions make side effects easier to represent in Haskell:

One way to represent side effects in a purely functional language is to model them as if they aren't side effects, by representing them as state changes in the "outside world". You don't need to grok the specifics of this, but the definition of the `IO` monad is:

  newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #))
i.e., it's a "pure" transformation of the "real world".

This allows you to define a "box" called `IO` that represents a computation that can perform a side-effect (by affecting the "real world"), then returning a value.

The real trick to this is that the "box" is entirely opaque to you: unlike a list or a `Maybe` where you know how to reach in and pull values _out_ (e.g., `head`, `last`, `fromJust`, etc.), `IO` doesn't allow you to do this*. Once you have something inside of an `IO` box, it's stuck there.

This means that you can separate the "impure" world from the "pure" world: you can't perform side effects arbitrarily — you're can only do so in an `IO` context that's intentionally "viral".

The functor/applicative/monad rules just make `IO` easier to use and consume:

  1. `Functor` allows you to "map" over the results of a computation
  2. `Applicative` allows you to chain computations together in order so side effects happen in sequence
  3. `Monad` makes it easier to repeatedly chain computations within a single `IO` context (so if you need to perform repeated side effects, you can "stay" in the outer context — `IO a` instead of `IO (IO (IO (IO (... (IO a)))))`)
This is just one way to represent side effects, and the monad rules are only really needed to make this representation ergonomic to actually use.

(*There is technically a way to "escape" the `IO` monad called `unsafePerformIO`, but you basically never need to use this. If you find yourself reaching for it, don't.)
_rend
·2 माह पहले·discuss
Sure! "Box" here is used to just abstractly describe a value that contains other values. Let's take a list as an example:

  [1, 2, 3] :: [Int]
Here, the "box" is a list, and inside of it are the values 1, 2, and 3.

As you know, `map` is an operation that converts the values inside of the box into other values; for example, adding 1 to every element:

  [1, 2, 3] :: [Int]
   |  |  |     (+ 1)
   v  v  v
  [2, 3, 4] :: [Int]
But the operation you perform with `map` doesn't need to keep the values of the same type:

  [ 1,   2,   3 ] :: [Int]
    |    |    |      (show)
    v    v    v
  ["1", "2", "3"] :: [String]
The operation can also produce new boxes! Since `String` is actually itself a list (`[Char]`), the result above is the same as

  [  1,     2,     3  ] :: [Int]
     |      |      |       (show)
     v      v      v
  [['1'], ['2'], ['3']] :: [[Char]]
In some cases, you might want to "flatten" this box-of-boxes together. In some languages this operation is called "flatten"; for lists in Haskell, it's called `concat`

  [['1'], ['2'], ['3']] :: [[Char]]
     |      |      |       (concat)
     v      v      v
  [ '1',   '2',   '3' ] :: [Char]
This example isn't terribly motivating, but you can see when you have deeper lists-of-lists how this might be handy:

  [[1,2,3], [4,5,6], [7,8,9]] :: [[Int]]
      |        |        |        (concat)
      v        v        v
  [1, 2, 3, 4, 5, 6, 7, 8, 9] :: [Int]
Here, we took a collection of boxes (`[[Int]]`) and combined them in order (sequentially) to produce a new box (`[Int]`).

What other languages call `flatMap` is just a `map` operation followed by a `flatten` operation. Very roughly, `Functor` gives you "map" (`map`), `Applicative` gives you "flatten" (`concat`), and `Monad` gives you "flatMap" (`concatMap`).

The power of these comes from considering different types of "boxes". `Maybe`, for example, works almost like a list that can contain up to 1 element, and its operations behave pretty much identically. Other types are interesting because how you define their "box-ness" can lead to interesting/useful results. It can be tough to envision how, e.g., a function could look like a "box", but it turns out that you can define rules for it that make it useful. (What does "map" look like for a function? Well, it turns out that mapping a function over another function is already just... function composition!)

You can go a lot deeper into these definitions, and it helps to look at some implementations to grok them better, but the core concepts themselves are not very complicated. The "magic" is in how you define the "boxes".
_rend
·2 माह पहले·discuss
My personal alternative take to the usual monad tutorial — greatly simplified:

"Functor", "Applicative", and "Monad" are all just generalizations of the concept of `map` and `flatMap`.

  1. Something is a "Functor" if you know how to call `map` on it, nothing more. "I can take a box of things and turn it into a box of other things, 1-to-1". On lists, for example, this is just `map` itself
  2. Something is an "Applicative" if you know how to call `map` on it, but also know how to take a non-boxed value and put it in a box, and also know how to combine boxes in order
  3. Something is a "Monad" if you know how to do all of the above, but also know how to call `flatMap` on it, nothing more. "I can take a box of things, turn each thing into a new box, and then combine them all in order". On lists, for example this is just `concatMap`
There's nothing really more complex to it, besides how you squint at various things (like functions) to fit them into the concept of `map` and `flatMap`.

To answer your questions more directly:

  1. Monads themselves are neither necessary nor sufficient to perform side effects in Haskell; they don't directly enable the effects, but they *do* help place guardrails on the actual unsafe, low-level code which *can* perform the effects, safely and in an ergonomic and composable way
  2. Yes, "Monad" is just a name for a recurring way to approach a problem. Like in most math and programming, a certain repeating pattern was noticed, and given a name. Because of the math origin of the term, you get "Monad" instead of "flat-mappable"
  3. Like any other tool, you reach for a monad when you have a monad-shaped problem. They're just one (powerful) tool for solving certain problems
_rend
·2 माह पहले·discuss
"Go ahead"?
_rend
·5 माह पहले·discuss
This is awesome! Love to see something new in this space, especially so heavily inspired by QuickSilver. The UI is slick and fast, and the fuzzy matching (and the match UI itself) is excellent.

If you're taking feedback, I've been a >decade-long user of LaunchBar, and I've yet to find another launcher that handles my most common actions quite as well (except maybe Alfred):

1. I launch a ton of URLs directly from LaunchBar, and it's a killer feature for me to be able to start typing a URL (not intending to match anything) and as soon as I type a period, LaunchBar converts the search to a URL (and inserts 'https://' and '.com'). e.g., if I type "abc.", LaunchBar will expand to "https://abc.com" with the ".com" highlighted for replacement (and hitting Return will open the URL immediately). Right now, if I want to do the same with Tuna and my default mode is Fuzzy Mode, I believe I need to hit '"' to enter Text Mode, type the URL, hit Tab, then search for the "Open URL" action (which also won't recognize a "bare" URL without the scheme, so won't show up for, e.g., "abc.com") — but happy to be wrong! I think it'd be swell if it were possible to configure Tuna to, on '.', convert into text mode, automatically insert "https://" and ".com", and automatically pre-populate the "Open URL" action so I could just hit Return to confirm and launch

2. I use the inline calculator a lot, and really like the "auto math" switch when typing digits (and really like the carve-out for 1Password, where typing '1' will show 1Password in fuzzy search instead of switching to the calculator); switching to text mode automatically on numeric input would be really helpful to do the same

3. I have a few custom search templates in LaunchBar I use all the time (several different search engines), and I'm not sure if it's possible to set up something similar directly inside of Tuna yet without writing custom services or an extension

Obviously, this is just how I use LaunchBar, and may not fit in with your vision of Tuna, but figured it might be some helpful food for thought! Thanks for your work on this :)
_rend
·5 माह पहले·discuss
This is awesome! The design is slick, and it really does feel right at home on a portable device. Appreciate the work that went into this.

Even more so, huge kudos for the performance tuning! The app launches instantly, so much so that I was initially a bit shocked. I'd forgotten what it feels like to tap a button and have something functional appear on screen with zero delay. When even the simplest apps have loading screens (and even built-in Settings/Reminders/Notes/Phone/etc. have a delay), this was really refreshing to see! I legitimately force-quit a bunch of apps on my phone to compare and nothing comes close on cold launch. Great work!
_rend
·6 माह पहले·discuss
This is Swift, where Type? is syntax sugar for Optional<Type>. Swift's Optional is a standard sum type, with a lot of syntax sugar and compiler niceties to make common cases easier and nicer to work with.