juan_gandhi: (Default)
Juan-Carlos Gandhi ([personal profile] juan_gandhi) wrote2012-07-02 12:24 pm
Entry tags:

наука и жизнь

Scala:
  scala> List(Set(1,2)).flatten == List(Set(2,1)).flatten
res3: Boolean = false


Бля.

[identity profile] sassa-nf.livejournal.com 2012-07-02 07:34 pm (UTC)(link)
да, прикольно. каноничного порядка в сете нет.

[identity profile] lomeo.livejournal.com 2012-07-02 07:39 pm (UTC)(link)
Зависит от Set:

import scala.collection.immutable._

scala> List(HashSet(1, 2)).flatten == List(HashSet(2,1)).flatten
res0: Boolean = true

[identity profile] sassa-nf.livejournal.com 2012-07-02 07:46 pm (UTC)(link)
ну в HashSet есть каноничный порядок

(no subject)

[identity profile] ivan-gandhi.livejournal.com - 2012-07-02 21:29 (UTC) - Expand

[identity profile] ivan-gandhi.livejournal.com 2012-07-02 08:18 pm (UTC)(link)
Вот правильный сет! Спасибо за идейку!

Sorry, could not resist

[identity profile] spamsink.livejournal.com 2012-07-02 07:37 pm (UTC)(link)
И так будет с каждым, кто не пользуется C++ STL.

[identity profile] sorhed.livejournal.com 2012-07-03 06:54 am (UTC)(link)
STL, конечно, неплохая библиотека. Её портит только вот это вот недоразумение, по ошибке считающееся языком программирования...

(no subject)

[identity profile] spamsink.livejournal.com - 2012-07-03 06:56 (UTC) - Expand

(no subject)

[identity profile] sorhed.livejournal.com - 2012-07-03 06:58 (UTC) - Expand

(no subject)

[identity profile] spamsink.livejournal.com - 2012-07-03 07:06 (UTC) - Expand

(no subject)

[identity profile] sorhed.livejournal.com - 2012-07-03 07:07 (UTC) - Expand

(no subject)

[identity profile] spamsink.livejournal.com - 2012-07-03 07:14 (UTC) - Expand

(no subject)

[identity profile] a-jelly.livejournal.com - 2012-07-04 12:35 (UTC) - Expand

(no subject)

[identity profile] ivan-gandhi.livejournal.com - 2012-07-03 16:33 (UTC) - Expand

[identity profile] lomeo.livejournal.com 2012-07-02 07:38 pm (UTC)(link)
См. реализацию вот этого класса и всё станет ясно:
https://github.com/scala/scala/blob/v2.9.2/src/library/scala/collection/immutable/Set.scala#L92

[identity profile] migmit.livejournal.com 2012-07-02 07:41 pm (UTC)(link)
Никакая реализация не оправдывает косяк интерфейса.

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-02 19:48 (UTC) - Expand

(no subject)

[identity profile] glocka.livejournal.com - 2012-07-02 19:53 (UTC) - Expand

(no subject)

[identity profile] ivan-gandhi.livejournal.com - 2012-07-02 19:54 (UTC) - Expand

(no subject)

[identity profile] migmit.livejournal.com - 2012-07-02 19:59 (UTC) - Expand

(no subject)

[identity profile] lomeo.livejournal.com - 2012-07-02 20:28 (UTC) - Expand

[identity profile] ivan-gandhi.livejournal.com 2012-07-02 07:53 pm (UTC)(link)
Реализация - это или следствие не вполне адекватного понимания, или признание грустной (гнусной) реальности.

ага

[identity profile] zhengxi.livejournal.com 2012-07-02 07:38 pm (UTC)(link)
scala> Set(1,2).toString == Set(2,1).toString
res11: Boolean = false

scala> Set(1,2).toList == Set(2,1).toList
res12: Boolean = false

Re: ага

[identity profile] ivan-gandhi.livejournal.com 2012-07-02 07:49 pm (UTC)(link)
Да, вот именно.
Проблема.

[identity profile] ralitza.livejournal.com 2012-07-02 07:50 pm (UTC)(link)
для меня первые строки - медитация

последнее слово - сигнал к ее окончанию.

[identity profile] cema.livejournal.com 2012-07-02 08:03 pm (UTC)(link)
Плохая, негодная Scala!

[identity profile] akalenuk.livejournal.com 2012-07-02 08:35 pm (UTC)(link)
Хм. Вот не знаю скалы, но кажется правильней было бы как-то так:
List(Set(1,2), order_fun)

Просто так привести множество в список нельзя же. Нужен антирефлексивный порядок, а откуда его взять?

Кстати. "List(Set(1,2,2)).flatten == List(Set(2,1,1)).flatten" ?

[identity profile] ivan-gandhi.livejournal.com 2012-07-02 08:42 pm (UTC)(link)
false

[identity profile] dvig-al.livejournal.com 2012-07-03 03:23 am (UTC)(link)
блин, читая переписку в рассылке, очень напомнило http://www.scala-lang.org/node/9021.
Edited 2012-07-03 03:24 (UTC)

[identity profile] ivan-gandhi.livejournal.com 2012-07-03 03:27 am (UTC)(link)
О как роскошно. Сидел ржал.

(no subject)

[identity profile] dvig-al.livejournal.com - 2012-07-03 03:45 (UTC) - Expand

[identity profile] aamonster.livejournal.com 2012-07-03 09:01 am (UTC)(link)
Какая прелесть =)
И ведь ни один э... хороший человек не посоветовал написать x.compare(y)

(no subject)

[identity profile] aamonster.livejournal.com - 2012-07-03 09:06 (UTC) - Expand

(no subject)

[identity profile] dvig-al.livejournal.com - 2012-07-03 09:20 (UTC) - Expand

(no subject)

[identity profile] aamonster.livejournal.com - 2012-07-03 09:25 (UTC) - Expand

[identity profile] nponeccop.livejournal.com 2012-07-03 05:26 am (UTC)(link)
Prelude Data.Set> toList (fromList [1, 2]) == toList (fromList [2,1])
Loading package array-0.3.0.2 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
True


хехе

[identity profile] huzhepidarasa.livejournal.com 2012-07-03 06:11 am (UTC)(link)
Ну дык. Профессура со своими когомологиями. Не хотят как все нормальные люди, кувалдой ;-)

[identity profile] sassa-nf.livejournal.com 2012-07-03 07:25 am (UTC)(link)
рано радуетесь. :)

http://ivan-gandhi.livejournal.com/2019207.html?thread=24711559#t24711559 - такой пример не существует? разве только по умолчанию в хаскеле это SortedSet.

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-03 08:34 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 09:11 (UTC) - Expand

(no subject)

[identity profile] thesz.livejournal.com - 2012-07-03 10:00 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 10:06 (UTC) - Expand

(no subject)

[identity profile] thesz.livejournal.com - 2012-07-03 10:43 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 10:52 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 10:29 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-03 11:41 (UTC) - Expand

(no subject)

[identity profile] eacher.livejournal.com - 2012-07-03 14:20 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-03 14:40 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-03 14:42 (UTC) - Expand

(no subject)

[identity profile] eacher.livejournal.com - 2012-07-03 14:50 (UTC) - Expand
(deleted comment)

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-03 14:53 (UTC) - Expand

(no subject)

[identity profile] eacher.livejournal.com - 2012-07-03 15:02 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 18:18 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-04 04:51 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-04 07:30 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 18:10 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-03 18:11 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 20:02 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-04 04:54 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-04 07:27 (UTC) - Expand

(no subject)

[identity profile] nponeccop.livejournal.com - 2012-07-04 07:38 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-04 07:39 (UTC) - Expand

[identity profile] eacher.livejournal.com 2012-07-03 06:11 am (UTC)(link)

$> ghci
GHCi, version 7.0.4: 
...
... done.
Prelude> :m Data.Set
Prelude Data.Set> let s1 = Data.Set.empty
...
... done.
Prelude Data.Set> let s2  = Data.Set.empty
Prelude Data.Set> let s11 = Data.Set.insert 1 s1
Prelude Data.Set> let s12 = Data.Set.insert 2 s11
Prelude Data.Set> let s21 = Data.Set.insert 2 s2
Prelude Data.Set> let s22 = Data.Set.insert 1 s21
Prelude Data.Set> s12 == s22
True
Edited 2012-07-03 06:13 (UTC)

[identity profile] sorhed.livejournal.com 2012-07-03 06:59 am (UTC)(link)
Анноит? Пиши камплейн репорть баг. :) Ведь баг же?

[identity profile] sorhed.livejournal.com 2012-07-03 07:10 am (UTC)(link)
Впрочем, действительно, не баг. Нужен SortedSet. Ещё в джаве был LinkedHashSet для таких целей.

[identity profile] eacher.livejournal.com 2012-07-03 07:26 am (UTC)(link)
>> Анноит?
ni razu

vidimo nado prodolzhit'...

fp : "odin i tot zhe argument - odin i tot zhe rezultat"

vyshe pokazano ravenstvo listov, nu dlya chistoty :


Prelude Data.Set> Data.Set.toList s12 == Data.Set.toList s22
True


point v tom, chto scala - javno ne "tort"

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 08:31 (UTC) - Expand

(no subject)

[identity profile] eacher.livejournal.com - 2012-07-03 09:20 (UTC) - Expand

(no subject)

[identity profile] eacher.livejournal.com - 2012-07-03 09:26 (UTC) - Expand

(no subject)

[identity profile] thesz.livejournal.com - 2012-07-03 10:03 (UTC) - Expand

(no subject)

[identity profile] sassa-nf.livejournal.com - 2012-07-03 10:17 (UTC) - Expand

(no subject)

[identity profile] eacher.livejournal.com - 2012-07-03 11:00 (UTC) - Expand