deniok: (Default)
[personal profile] deniok
Сегодня на stackoverflow, отвечая на вопрос, Andreas Hammar привёл хорошие примеры. Сохраняю на будущее, как простые задачки для студентов
data    D a = D a
data    S a = S !a
newtype N a = N a

constD x (D y) = x
constS x (S y) = x
constN x (N y) = x
Какие из следующих вызовов завершат свою работу как Deep Thought, а какие как Earth?
D undefined `seq` 42
S undefined `seq` 42
N undefined `seq` 42
constD 42 undefined
constS 42 undefined
constN 42 undefined

Date: 2012-11-27 08:39 am (UTC)
From: [identity profile] lionet.livejournal.com
newtype — это создание фантомного конструктора/тэга, которого потом в рантайме не существует. Фактически, «newtype N a» это то же самое, что «a» в рантайме. Отсюда взрывание третьего и невзрывание шестого примеров. Строгий !a в типе S приводит к попытке форсирования undefined во втором примере, поэтому он взрывается. Остальное стандартно.

Date: 2012-11-27 08:48 am (UTC)
From: [identity profile] deni-ok.livejournal.com
ага, всё верно.

Date: 2012-11-28 01:13 pm (UTC)
From: [identity profile] kurilka.livejournal.com
а что это за термины Deep Thought и Earth?

Date: 2012-11-28 01:17 pm (UTC)
From: [identity profile] deni-ok.livejournal.com
из The Hitchhiker's Guide to the Galaxy. Deep Thought после семи с половиной миллионов лет раздумья ответил 42 на один вопрос, и пошло-поехало.

Date: 2012-11-28 01:23 pm (UTC)
From: [identity profile] kurilka.livejournal.com
а земля-то тут при чём?

Date: 2012-11-28 01:39 pm (UTC)
From: [identity profile] deni-ok.livejournal.com
Although often mistaken for a planet, Earth is in reality the greatest supercomputer of all time, designed by the second greatest supercomputer of all time, Deep Thought, to calculate the Ultimate Question of Life, The Universe and Everything (to which the answer is 42). It was built by the then-thriving custom planet industry of Magrathea to run a ten-million-year program in which organic life would play a major role.

Five minutes before the program was to finish running, Earth was destroyed by the Vogons, allegedly to make way for a hyperspace bypass but in fact to prevent the Ultimate Question being discovered, as it was seen as a threat to the psychiatric industry.

Date: 2012-11-28 01:42 pm (UTC)
From: [identity profile] kurilka.livejournal.com
а, чот я совсем уже книжку позабыл, сорри

Date: 2012-11-28 01:43 pm (UTC)
From: [identity profile] deni-ok.livejournal.com
Фильм посмотри, он вполне достоин книжки.

Date: 2012-11-28 01:49 pm (UTC)
From: [identity profile] kurilka.livejournal.com
Не, мне он как-то не особо понравился в отличие от

Profile

deniok: (Default)
deniok

February 2022

S M T W T F S
  12345
6789101112
13141516171819
20212223 242526
2728     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 14th, 2025 04:39 am
Powered by Dreamwidth Studios