Date: 2017-04-05 11:20 pm (UTC)
bytebuster: (Villeret1-YesNo)
From: [personal profile] bytebuster
Потерялся после 13-го слайда. :( Но считаю, как для самоучки без базового матана по теории категорий — нормально. :)

Вот хорошие слайды, очень близко к вашей лекции: Railway Oriented Programming



Я когда-то подобную штуку писал на коленке и наугад (без матана) для своей парсилки тайского языка. Там решение выглядело так, что кроме результата вычисления, тянулся еще description и дерево лемм.

Date: 2017-04-05 11:35 pm (UTC)
bytebuster: (Default)
From: [personal profile] bytebuster
Начало я понял, это ж типичная проблема, сплошь и рядом возникает при кодировании. Но вот потом я уперся в то, что если у нас есть строго последовательность вычислений (вот там, где на 12/13-м слайде про DOB), то чаще всего дальнейшие вычисления не имеют смысла.

А значит, надо останавливаться и сообщать об ошибке.
Одной! Потому что следующее вычисление почти всегда зависит от предыдущих.

А если не зависит, то речь идет о concurrent tasks, и программист должен был бы это разделить средствами языка. А если не разделил, то бить по рукам, потому что он подложил мину под будущее scalability.

Разве нет?

Date: 2017-04-05 11:39 pm (UTC)
bytebuster: (Default)
From: [personal profile] bytebuster
Тайский. Парсить. Parsec'ом. Точнее, его FSharp'овым клоном, FParsec. Собственно, автор ФПарсека меня на StackOverflow и пригласил.

Он потом еще где-то в блоге писал, что это единственный известный ему случай, где монадическим парсером парсится natural human language; он-то привык к DSL'ям. :))

Точнее, не сегментации, а syllabification. Потому там и FParsec, что накопительно парсим и, в случае чего, rollback.
Edited Date: 2017-04-05 11:41 pm (UTC)

Date: 2017-04-06 07:35 am (UTC)
From: [personal profile] sassa_nf
Well, flattening the structure also means you cannot distinguish absence of the object:

was: {x: {y: z, s: t}} - missing x means both y and s are also missing
flat: {x.y: z} - is x missing or not?

Date: 2017-04-06 07:39 am (UTC)
From: [personal profile] sassa_nf
rather, the piece that produces x: {y:..., z:...} now needs to be aware of where in the resulting structure it is. And the piece producing y:... needs to be aware where in the x:... it is. Etc.

Date: 2017-04-06 07:27 pm (UTC)
From: [personal profile] sassa_nf
Right. So how does one produce a flat structure from a tree?

function* toJSON(x) {
  if (typeof x === 'string') {
    yield '"';
    yield escape(x);
    yield '"';
    return;
  }
  if (typeof x === 'number') {
...  }
  if (typeof x === 'boolean'
...
  }
  yield '{';
  let first = true;
  for (let k in x) {
    if (!first) yield ',';
    first = false;
    yield '"' + k + '": ';
    yield* toJSON(x[k]);
  }
  yield '}';
}


Straightforward streaming of keys, values, delimiters. No one is aware of anyone's parents or children.

If we were to flatten it first, then somewhere need to distinguish that they are part of objects, so the correct keys can be produced in the output.

function* toJSON(k, x) {
  if (typeof x === 'object') {
    for (let k1 in x) {
      yield* toJSON(k? k + '.' + k1: k1, x[k1]);
    }
    return;
  }
  if (k) {
    yield '"';
    yield k;
    yield '":';
  }

  if (typeof x === 'string') {
    yield '"';
    yield escape(x);
    yield '"';
    return;
  }
  if (typeof x === 'number') {
...  }
  if (typeof x === 'boolean'
...
  }
}

Date: 2017-04-06 07:33 pm (UTC)
From: [personal profile] sassa_nf
Not sure what you mean by 1-1 correspondence.

[{"a": 1}, {"b": 2}] JSON has a corresponding flat structure of ....?

ok, then:
{"a":[{"b": 1}, {"c": 2}]} JSON has a corresponding flat structure of "a.0.b: 1", "a.1.c: 2". But what JSON does the flat structure "a.0.b: 1", "a.2.c: 2" correspond to?

Date: 2017-04-06 08:27 pm (UTC)
From: [personal profile] sassa_nf
No, it's not quite like that.

> x = {0:1, 2:3}
{ '0': 1, '2': 3 }
> x.length
undefined
> [1,,3]
[ 1, , 3 ]
> [1,,3].length
3

Date: 2017-04-06 09:14 pm (UTC)
From: [personal profile] sassa_nf
It's not about arrays with holes. JSON for them will have null instead of a hole. That's not the same as {0: 1, 2: 3}. Arrays have length and order of elements.

Maybe I am a bit slow, but yes, we can ascribe properties to certain objects. But you need to encode those properties so that you can restore them upon decoding. Like in JSON those properties are encoded by using square brackets. In a flat structure everything looks the same, so you need to invent markers, like extra constructed fields (length? plus _isArray?).

I recall what stunts people adopt to read a list of properties from Java's .properties files, which _are_ flat. :-)
Edited Date: 2017-04-06 09:21 pm (UTC)

Date: 2017-04-06 03:48 pm (UTC)
arstmas: (Default)
From: [personal profile] arstmas
кот хорош

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
181920 21 222324
25 262728 293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 31st, 2025 05:06 am
Powered by Dreamwidth Studios