Created
March 10, 2015 02:36
-
-
Save alexandre/328efcbf95a391e04788 to your computer and use it in GitHub Desktop.
haskell-beginners
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Hi guys/girls | |
| <ubbersith> I'm trying to repeat a python test with Haskell...can someone help me? https://gist.github.com/alexandre/442ec9dc189e222d3aae | |
| <ubbersith> I didn't understand why the interpreter don't just evaluates the first acess (it is trying evaluate everything?) | |
| <bitemyapp> ubbersith: you created an infinite list. | |
| * firebird1 (~firebird@117.192.191.140) has joined #haskell-beginners | |
| <bitemyapp> ubbersith: actually, cyclic reference, sorry. | |
| <bitemyapp> > take 10 $ cycle [1, 2] | |
| <lambdabot> [1,2,1,2,1,2,1,2,1,2] | |
| <ubbersith> ok, but my bool test (==) should works, shouldn't? | |
| <bitemyapp> no. | |
| <bitemyapp> the data structure the Python code creates isn't well-typed in Haskell, it has the infinite type | |
| <bitemyapp> so it doesn't even really make sense. | |
| <bitemyapp> even if you wrote code that constructed such a value, the type-checker would swat you. | |
| <ubbersith> hmmm, ok. Thanks =] | |
| <bitemyapp> ubbersith: there ways of expressing similar notions in Haskell without making something sensical. | |
| <bitemyapp> [(a, b, [c])] is well-typed. | |
| <bitemyapp> because really what you're expressing is a list of a tuple of a value, a value, and a list of values. | |
| <bitemyapp> but you lifted "more list" into the list in a way that doesn't make a lot of sense. | |
| <ubbersith> hmmm, I thought the interpreter was evaluate the last element, only when I access it. | |
| <bitemyapp> the problem is the definition itself | |
| <ubbersith> yeah,I know...that's just I test...something that I think curious... | |
| <ubbersith> (I know -> it not make sense) | |
| <bitemyapp> there are ways to define infinite lists, but a naively self-referencing definition like that is _|_ | |
| <bitemyapp> neat code though, had me thinking for a moment with that Python code. | |
| <bitemyapp> I've used Python for a decade and never used that trick before. | |
| <ubbersith> =] | |
| <ski> ubbersith : there is no "identical object" comparision in Haskell | |
| <ubbersith> ski: hmmm, thank you man. | |
| * coltfred (~coltfred@71.15.210.194) has joined #haskell-beginners | |
| <ski> > let x = [1,2]; y = x ++ y in (drop 2 . drop 2 . drop 2 . drop 2) y == y -- this hangs, as it tries to traverse the cyclic lists until it either hits the end, or a discrepancy | |
| <lambdabot> mueval: ExitFailure 1 | |
| <ski> ubbersith ^ | |
| <ski> (btw, that `(drop 2 . drop 2 . drop 2 . drop 2) y' is just another way of writing `drop 2 (drop 2 (drop 2 (drop 2 y)))') | |
| <ski> (note that in my version, it's not the element at index `2' in `y' which is equal to `y', but rather it's the remainder of the list `y' after dropping the first two elements which is equal to `y' (though it can't be detected internally from Haskell), as suggested by the above evaluation being aborted due to timeout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment