Haskell, newtype vs data
Nov. 27th, 2012 12:36 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Сегодня на 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
no subject
Date: 2012-11-27 08:39 am (UTC)no subject
Date: 2012-11-27 08:48 am (UTC)no subject
Date: 2012-11-28 01:13 pm (UTC)no subject
Date: 2012-11-28 01:17 pm (UTC)no subject
Date: 2012-11-28 01:23 pm (UTC)no subject
Date: 2012-11-28 01:39 pm (UTC)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.
no subject
Date: 2012-11-28 01:42 pm (UTC)no subject
Date: 2012-11-28 01:43 pm (UTC)no subject
Date: 2012-11-28 01:49 pm (UTC)