- June 13th, 2016:
You want this list:[1, -1, 1, -1, ...]
How would you produce this value in #Haskell ?- Wai Lee Chin Feman @wchinfeman
https://gist.github.com/skatenerd/08d70c45499e1610206a
(set plop to be identity, and set transformstate to be (*) -1) - Philipp Maier @AkiiZedd `
iterate negate 1
’ - Patrick Mylund @pmylund
concat $ repeat [1, (-1)]
- Gary Fixler @gfixler No need for the parens in a list.
- Jeff Foster @fffej and Kevin Meredith @Gentmen
iterate (* (- 1)) 1
- Spencer Janssen @spencerjanssen and Андреев Кирилл @nonaem00
cycle [1, -1]
- Philipp Maier @AkiiZedd:
I’m curious: Since concat is O(n) wouldn’t it take more and more time depending on how many items you take? - Patrick Mylund @pmylund Looks like they compile to the same thing https://gist.github.com/patrickmn/9a92ab2a088018b2c0631f3bcfd60ebe
- Philipp Maier @AkiiZedd I’m actually surprised the compiler can optimise this away :o Thanks for showing me
ddump-simpl
! - Eyal Lotem @EyalL
concat
isfoldr (++)
, notfoldl
. O(1) work is done to produce the next item.[1,-1]++([1,-1]++(...
- Philipp Maier @AkiiZedd:
- Wai Lee Chin Feman @wchinfeman
- David Turner @DaveCTurner I'd actually write '
cycle [1,-1]
' but I like the elegant, alliterative obscurity of 'iterate negate 1
' - Fatih Karakurt @karakfa
alt=1:[-x|x<-alt]
Incorporates strong typing over predicate logic programming, and, conversely, incorporates predicate logic programming into strongly typed functional languages. The style of predicate logic is from Prolog; the strongly typed functional language is Haskell.
Thursday, July 14, 2016
1HaskellADay 1Liners June 2016
Subscribe to:
Post Comments (Atom)
1 comment:
x = 1 : -1 : x
or
(let x = 1 : -1 : x in x)
Post a Comment