Search Haskell Channel Logs

Monday, January 30, 2017

#haskell channel featuring nitrix, roxxik, Xnuk, infandum, Vtec234, benneh, and 17 others.

Profpatsch 2017-01-30 04:45:18
For [] it just pattern matches
orion 2017-01-30 04:45:53
jophish: Are you happy with opaleye?
jophish 2017-01-30 04:46:25
orion: for the most part :)
Profpatsch 2017-01-30 04:48:35
:exf Bool -> (a -> b) -> a -> b
exferenceBot 2017-01-30 04:48:40
\ b1 f2 c -> f2 (bool c c b1)
roxxik 2017-01-30 04:50:26
?src null
lambdabot 2017-01-30 04:50:26
null [] = True
lambdabot 2017-01-30 04:50:26
null (_:_) = False
roxxik 2017-01-30 04:50:34
?src (==)
lambdabot 2017-01-30 04:50:34
x == y = not (x /= y)
roxxik 2017-01-30 04:50:40
?src (==) @ []
lambdabot 2017-01-30 04:50:40
Source not found. Take a stress pill and think things over.
roxxik 2017-01-30 04:50:43
hmmm
quchen 2017-01-30 04:51:01
It's a static database.
roxxik 2017-01-30 04:51:05
oh
quchen 2017-01-30 04:51:06
No fanciness involved.
quchen 2017-01-30 04:51:09
Lambdabot @src database: https://github.com/lambdabot/lambdabot/blob/master/lambdabot/State/source
Vtec234 2017-01-30 04:51:20
wait, what
Vtec234 2017-01-30 04:51:27
?src (/=)
lambdabot 2017-01-30 04:51:27
x /= y = not (x == y)
Vtec234 2017-01-30 04:51:33
?src (==)
lambdabot 2017-01-30 04:51:33
x == y = not (x /= y)
Vtec234 2017-01-30 04:51:35
what
shapr 2017-01-30 04:51:40
Vq: GOOD MORNING!
roxxik 2017-01-30 04:51:59
?src [] (==)
lambdabot 2017-01-30 04:51:59
[] == [] = True
lambdabot 2017-01-30 04:51:59
(x:xs) == (y:ys) = x == y && xs == ys
lambdabot 2017-01-30 04:51:59
_ == _ = False
Vtec234 2017-01-30 04:52:53
why is equality defined in terms of inequality defined in terms of equality defined in terms of inequality defined in terms of equality defined in terms of inequality defined in <>
lyxia 2017-01-30 04:53:03
Vtec234: these are just the default implementations. you're supposed to provide at least one of (==) or (/=) when defining the instance
lyxia 2017-01-30 04:53:18
Vtec234: the default implementation then takes care of defining the other
roxxik 2017-01-30 04:54:07
in the docs it says `Minimal complete definition: (==) | (/=)` ;)
jophish 2017-01-30 04:54:16
Profpatsch: did you mean : Bool -> (a -> a) -> a -> a ?
ph88 2017-01-30 04:54:45
hi guys, i'm getting this error about Arbitrary https://paste.fedoraproject.org/541149/14857916/ i'm staring a bit blind here, anyone some pointers on what i could check to figure out why this error occurs ?
roxxik 2017-01-30 04:55:59
:exf (s -> (a,s)) -> (a -> s -> (b,s)) -> s -> (b,s)
exferenceBot 2017-01-30 04:56:00
\ f1 f2 c -> let ((,) g h) = f1 c in f2 g h
ph88 2017-01-30 04:56:30
i guess i will just try to reduce the type until the error goes away :/
roxxik 2017-01-30 04:57:13
:exf Maybe a -> (a -> Maybe b) -> Maybe b
exferenceBot 2017-01-30 04:57:13
(Control.Monad.>>=)
roxxik 2017-01-30 04:57:24
oh... that's a little disappointing
Profpatsch 2017-01-30 04:58:33
jophish: Well, I meant f b g = bool id g b
roxxik 2017-01-30 04:59:09
:exf ((a -> r) -> r) -> (a -> ((b -> r) -> r) -> ((b -> r) -> r)
exferenceBot 2017-01-30 04:59:09
could not parse input type: ParseFailed (SrcLoc "inputtype.hs" 1 60) "Parse error: EOF"
roxxik 2017-01-30 04:59:16
:exf ((a -> r) -> r) -> (a -> ((b -> r) -> r)) -> ((b -> r) -> r)
exferenceBot 2017-01-30 04:59:16
\ f1 f2 f3 -> f1 (\ f -> f2 f f3)
roxxik 2017-01-30 04:59:45
it's nice how the bind implementations (minus newtypes) can just be derived
roxxik 2017-01-30 05:00:40
:t \f1 f2 f3 -> f1 (\f -> f2 f f3)
lambdabot 2017-01-30 05:00:42
((t1 -> t3) -> t) -> (t1 -> t2 -> t3) -> t2 -> t
ph88 2017-01-30 05:03:32
lyxia, do you have an idea perhaps? i just tested, if i put 5 things in that tuple it works, at the 6th it breaks
lyxia 2017-01-30 05:07:00
ph88: what version of quickcheck are you using
ph88 2017-01-30 05:07:48
QuickCheck-2.8.2
Xnuk 2017-01-30 05:08:34
??ㄱ자
Xnuk 2017-01-30 05:08:38
sorry
lep-delete 2017-01-30 05:09:38
ㅅㅅ
lyxia 2017-01-30 05:09:57
ph88: Arbitrary for 6-tuples was added in 2.9
lyxia 2017-01-30 05:10:16
the blame is here https://github.com/nick8325/quickcheck/blame/master/Test/QuickCheck/Arbitrary.hs#L550
ph88 2017-01-30 05:10:17
:(
ph88 2017-01-30 05:10:38
perhaps i can say to stack to use this newer quickcheck version ?
benneh 2017-01-30 05:10:53
http://lpaste.net/351789 <- Does this function exist anywhere already? It looks a bit like runStateT, but it's not.
ph88 2017-01-30 05:11:11
why was the blame there ? the highlighted line is a 7-tuple
lyxia 2017-01-30 05:11:31
ph88: oh you're right, I forgot to move the highlight up
ph88 2017-01-30 05:11:56
but the 6-tuple looks ok to me, don't see a mistake
lyxia 2017-01-30 05:12:16
there's no mistake
lyxia 2017-01-30 05:12:21
it's just not in your version
lyxia 2017-01-30 05:12:49
ph88: my point was that the commit where these instances were included happened after 2.8.2.
ph88 2017-01-30 05:12:52
i'm on lts-7.15 too bad it still had the old QC :/
ph88 2017-01-30 05:12:59
ah ok cool
ph88 2017-01-30 05:13:01
thanks for looking
lyxia 2017-01-30 05:13:42
I'd say go for it if you can upgrade quickcheck.
ph88 2017-01-30 05:14:13
i will try to add it as extra-deps in stack.yaml
ph88 2017-01-30 05:14:24
the latest lts is still on quickcheck-2.8.2 don't know why
MarcelineVQ 2017-01-30 05:16:10
the lts's goal isn't to be up to date, if you want more bleeding edge you might use the nightly resolver, or extra-deps
ph88 2017-01-30 05:16:49
oh well the new lts releases happen so quickly that i already felt like i was on bleeding edge :P
MarcelineVQ 2017-01-30 05:16:54
possibly in this case you could even just copy that arbitrary instance, I"m not sure how generics work and all that
ph88 2017-01-30 05:16:59
every time i start a new project it gets to a new lts release
nogid 2017-01-30 05:20:29
Can someone debunk this? C++ is pure: Consider that a C++ program actually runs at compile time (type system computations, constexpr evaluations). When the runtime loader (ld-linux.so) interprets the resulting binary, it is merely following the computation recipe returned by the C++ program at compile time. So all side-effects occur outside of the scope of the C++ program.
nitrix 2017-01-30 05:20:42
ph88: Maybe it's Haskell that cannot keep up with you!
nitrix 2017-01-30 05:21:10
ph88: Everyday, new project :P ?
tdammers 2017-01-30 05:21:17
nogid: it's a stab at how Haskell "cheats" itself into being pure by declaring its runtime to be outside the realm of the language itself
MarcelineVQ 2017-01-30 05:21:27
i don't really care what c++ does, not that I represent any significant opinion
Cale 2017-01-30 05:21:37
nogid: Well, those parts of a C++ program are pure, but that doesn't really constitute very much of the execution of a typical C++ program
tdammers 2017-01-30 05:21:42
nogid: the takeaway is that whether a language is pure or not is a matter of how you define its boundaries
ph88 2017-01-30 05:22:02
nitrix, no no, more like every day new lts and 1 new project a month :P
nogid 2017-01-30 05:22:17
tdammers: what has me stumped is that any argument that works can be applied just the same to Haskell's IO monad
quchen 2017-01-30 05:22:18
The universe is a closed system in the same way C++ is pure. If you make a circle big enough, everything's on the inside.
Cale 2017-01-30 05:22:26
nogid: Haskell is interesting because you can actually write a significant fraction of your program in a setting where effects don't occur.
Cale 2017-01-30 05:22:41
nogid: Nobody's claiming that execution of IO actions is pure.
tdammers 2017-01-30 05:22:42
nogid: not really; IO itself is pure, the runtime that interprets it is not
Cale 2017-01-30 05:23:21
But *evaluation* in Haskell is pure (deterministic, referentially transparent, effect free).
dfeuer 2017-01-30 05:23:36
Except for lazy IO.
nogid 2017-01-30 05:23:37
tdammers: couldn't you say "C++ compilation is pure, the runtime that interprets it is not"?
Cale 2017-01-30 05:23:48
dfeuer: Yes, that's fair enough :)
tdammers 2017-01-30 05:24:06
nogid: that would be a bit confusing, considering how compilation is impure in the sense that it reads source files and writes object files
nogid 2017-01-30 05:24:20
So evaluation in Haskell is the equivalent of compilation in C++, and evaluation in C++ is the equivalent of interpretation in Haskell?
nogid 2017-01-30 05:24:25
Just a matter of terminology?
nitrix 2017-01-30 05:24:37
nogid: You're conflating compilation, execution and evaluation.
dfeuer 2017-01-30 05:24:42
Cale: also see https://ghc.haskell.org/trac/ghc/ticket/11760 for an interesting bug.
Cale 2017-01-30 05:24:47
nogid: Well, "equivalent" until you actually consider what those things accomplish.
ph88 2017-01-30 05:25:06
lyxia, i just compiled all the rules of my parser for the first time :D now i still have to implement all the pretty printers (which there was a generic pretty print) and after that i have to run it with quickcheck. And quickcheck will find bugs because i need a symbol table which i have not implemented yet
nogid 2017-01-30 05:25:47
Cale: C++ can do any arbitrary computation at compile time, and any pure computation at runtime.
Cale 2017-01-30 05:26:07
nogid: "Can do" and "It's reasonable to architect your software that way" are two very different things.
Vtec234 2017-01-30 05:26:19
nogid: i think you meant it the other way around
nogid 2017-01-30 05:26:38
Vtec234: I mean it can do both. Anything at compile-time is necessarily pure.
Cale 2017-01-30 05:26:41
and yeah, you meant the other way around
nogid 2017-01-30 05:26:46
Vtec234: But you can also do pure computations at runtime
nitrix 2017-01-30 05:26:49
nogid: I highly doubt you can query a remote server during compilation.
Vtec234 2017-01-30 05:27:03
nogid: pure at compile time, arbitrary at runtime. it cannot do arbitrary things at compile-time
nitrix 2017-01-30 05:27:08
nogid: You must've meant the reverse.
nogid 2017-01-30 05:27:10
nitrix: But haskell can't query a remote server during evaluation time! Only at *interpretation* time
nogid 2017-01-30 05:27:31
and interpretation is by no means pure
tdammers 2017-01-30 05:27:39
actually, haskell can query remote servers at compile time
nogid 2017-01-30 05:27:43
it's just shifting the definitions
tdammers 2017-01-30 05:27:48
with TemplateHaskell at least
nogid 2017-01-30 05:27:52
well so Haskell is even less pure than C++ ;)
nogid 2017-01-30 05:27:58
if it can do that during compilation time
mmaruseacph2 2017-01-30 05:28:08
only with certain extensions
nogid 2017-01-30 05:28:18
I know, I'm just joking now, but it's something to be considered
Cale 2017-01-30 05:28:19
nogid: But even so, practically nobody encodes very much of the work that their C++ program has to do as template expansion, because that is entirely unreasonable -- the language is very much not designed to make that easy.
nitrix 2017-01-30 05:28:20
nogid: These extensions aren't Haskell though.
mmaruseacph2 2017-01-30 05:28:21
and those extensions place the onus on the programmer to ensure correctnes
ph88 2017-01-30 05:28:36
anyone know of a generic pretty printer that doesn't print stuff like show prints it ?
Cale 2017-01-30 05:29:00
nogid: The template language, while Turing complete, is just not very expressive.
tdammers 2017-01-30 05:29:00
actually TH doesn't do that; it still maintains the pure evaluation / impure execution separation
nogid 2017-01-30 05:29:08
Cale: but C++ programs are very often structured in a way such that individual functions are side-effect free
tdammers 2017-01-30 05:29:30
it's just that it allows you to hook into a compile-time cycle of evaluation and execution as well
Cale 2017-01-30 05:29:32
nogid: Sure, but you can't take advantage of, or rely upon this in any way.,
quchen 2017-01-30 05:29:33
ph88: This one formats Show stuff nicely, https://hackage.haskell.org/package/show-prettyprint
nogid 2017-01-30 05:29:35
Cale: the implementation details of those functions may leverage side-effects and mutations as a performance optimization, but that's entirely invisible from the outside
tdammers 2017-01-30 05:30:03
so you write pure code that gets executed by an impure runtime to generate AST for pure code that gets executed by an impure runtime
nogid 2017-01-30 05:30:19
tdammers: pretty much
ph88 2017-01-30 05:30:22
quchen, that package outputs stuff like show!
Cale 2017-01-30 05:30:25
nogid: The C++ type system can't tell you that they're side effect free, the compiler may or may not be able to discover it and leverage it, but as a programmer, there's no way of knowing without carefully inspecting every line of source code.
quchen 2017-01-30 05:30:35
ph88: Except for readability, yes.
nitrix 2017-01-30 05:30:46
nogid: You're still confused. For the sake of simplicity, I'll bundle execution and evaluation together, but in reality, these also have important distinction in the context of a lazy-evaluated language like Haskell. Which leaves us with two parts to talk about: the language according to the specification and the runtime that runs it.
ph88 2017-01-30 05:30:47
yes but i don't want that :/
ph88 2017-01-30 05:31:29
quchen, when i have tuple ("hello ", "world") i want "hello world" and not "(\"hello \", \"world\")"
nitrix 2017-01-30 05:31:29
nogid: With Haskell, your entire program is pure and its purpose is to build an ever increasingly complex IO "recipe", which is then given to the runtime system.
quchen 2017-01-30 05:31:51
ph88: If you're looking for a prettyprinter, the wl-pprint universe is the de facto standard, with many choices available. wl-pprint-ansi is currently the most popular option. If you're looking for documentation, I forked it and added truckloads of examples and explanations, a relatively recent Haddock rendering is online here: https://quchen.github.io/ansi-wl-pprint-docdump/wl-pprint-1/index.html
nogid 2017-01-30 05:31:55
nitrix: but that's just shifting definitions around
lyxia 2017-01-30 05:32:05
ph88: how is that generic
nitrix 2017-01-30 05:32:09
nogid: As far as working with Haskell, from its type system to everything else specified by the Haskell Report, you'll be working in a pure, referentially transparent, environment.
nogid 2017-01-30 05:32:11
nitrix: I agree that in Haskell you can see from the signature of a function that it is definitely pure
nitrix 2017-01-30 05:32:15
nogid: It's not.
ph88 2017-01-30 05:32:24
lyxia, you can inspect the structure of the tuple no ?
nogid 2017-01-30 05:32:28
nitrix: But any program doing reasonable work will have a lot of impure functions (interpretation-time, that is)
nitrix 2017-01-30 05:33:05
nogid: You have to understand that the effects you want the runtime to achieve are going to reflect in the types of your functions in a pure language.
lyxia 2017-01-30 05:33:09
ph88: but to do what you want you need to look at the types of each component of the tuple
nitrix 2017-01-30 05:33:26
nogid: The fact we have to accomodate effects at the type level is exactly what makes Haskell so safe.
Cale 2017-01-30 05:33:27
nogid: Evaluation is the process of reducing expressions to values (typically for the purposes of pattern matching / case analysis). In Haskell this has essentially no effects.
dfeuer 2017-01-30 05:33:35
Cale: you have PMs.
nogid 2017-01-30 05:33:44
Cale: Evaluation means something else in C++ though.
Cale 2017-01-30 05:34:05
nogid: Sure, evaluation can do a lot more stuff in C++
nogid 2017-01-30 05:34:17
Cale: the definition of evaluation in C++ encompasses what Haskell calls "interpretation"
nitrix 2017-01-30 05:34:21
nogid: It's pure in the denotational sense.
nogid 2017-01-30 05:34:24
So comparing the two is Apples-to-Oranges
nitrix 2017-01-30 05:34:31
nogid: Operationally, how Haskell is implemented is irrelevant.
Cale 2017-01-30 05:34:41
nogid: Right, there's no clean separation in C++ between what Haskell programmers call evaluation and execution
ph88 2017-01-30 05:34:59
lyxia, yes but for type String it's easy to define a default pretty printing function for it
Cale 2017-01-30 05:35:21
nogid: You can try to draw a line which is up at the level of template expansion, but that's not really a very reasonable analogy from a pragmatic standpoint.
Cale 2017-01-30 05:35:54
(because if you tried to translate any sizeable Haskell program into C++ while maintaining those lines, you'd lose all your hair and teeth in the process)
ph88 2017-01-30 05:36:04
lyxia, and for my own custom types i can define a function to pretty print it. I have type T (terminal) used everywhere, and it's the only type that needs to be printed. But now i have to write 150 pp functions over structures. So ye a package would come in handy ^^
nogid 2017-01-30 05:36:10
So to sum it up, the advantage Haskell gives you over a language like C++ is guaranteed type-system-enforced annotations for whether or not a function is pure at interpretation time.
Cale 2017-01-30 05:36:20
That's *one* advantage
Cale 2017-01-30 05:36:28
There are a large number of other ones
Cale 2017-01-30 05:36:32
But yes, that's a big one
ph88 2017-01-30 05:36:41
quchen, good work on the documentation :) at the moment i implemented a few functions with Text.PrettyPrint.Leijen.Text
dfeuer 2017-01-30 05:36:47
I'm a huge fan of some of Haskell's type system features.
nogid 2017-01-30 05:36:57
In the context of pure/impure, that seems to be the only advantage. Everything else is just bending the definitions.
nitrix 2017-01-30 05:37:00
nogid: There are many others; like equational reasoning.
nogid 2017-01-30 05:37:07
Not to say it doesn't have other advantages.
Vq 2017-01-30 05:37:12
shapr: GOOD EVENING!
quchen 2017-01-30 05:37:23
ph88: My fork is also Text-based in case that's important to you. :-) https://github.com/quchen/prettyprinter/
dfeuer 2017-01-30 05:37:23
The fancy type system also relies on purity in some ways.
nogid 2017-01-30 05:37:29
nitrix: that sort of follows from the guaranteed purity annotations
shapr 2017-01-30 05:37:31
Vq: oh hai! how's code?
Vq 2017-01-30 05:38:14
shapr: Very dynamically typed unfortunately. :(
lyxia 2017-01-30 05:38:38
ph88: if your implementations all look the same, consider using Generics.
shapr 2017-01-30 05:38:40
Vq: yeah, I'm reading about project m36 while I wait for my dynamically typed code to build.
nogid 2017-01-30 05:38:42
Now for practical reasons, I've never written a function in C++ and wondered about whether it's pure or not. In my experience it's always obvious to the programmer (unless it was written by someone else and you're just reading the code).
quchen 2017-01-30 05:39:05
Most code I read is by someone else.
Cale 2017-01-30 05:39:08
nogid: (unless it was written by someone else and you're just reading the code) <-- this is important
quchen 2017-01-30 05:39:12
Me 6 months ago is an example of someone else.
Vq 2017-01-30 05:39:17
shapr: m36? What dynamically typed language has long build times?
nogid 2017-01-30 05:39:28
So Haskell seems like it could provide advantages when multiple different programmers are working on a code-base and are not disciplined enough to document the side-effects of their functions.
shapr 2017-01-30 05:39:40
Vq: our build system is slow, not our language
shapr 2017-01-30 05:39:51
Vq: and I'm reading https://github.com/agentm/project-m36/blob/master/docs/15_minute_tutorial.markdown
Cale 2017-01-30 05:39:54
nogid: It's also important that the compiler holds you to task for your own work.
Cale 2017-01-30 05:40:04
nogid: I *constantly* make mistakes, and am aware of this fact
Cale 2017-01-30 05:40:26
The fact that the compiler is catching the vast majority of them is really really helpful.
lyxia 2017-01-30 05:40:27
ph88: Do you have more examples of outputs you want to have
shapr 2017-01-30 05:40:39
Yeah, give me all the crutches, because I am imperfect.
shapr 2017-01-30 05:41:30
nogid: also, you can code faster when the type system is checking for problems.
nogid 2017-01-30 05:41:34
Cale: in my experience with reasonable modern C++, the compiler also catches almost every mistake
lyxia 2017-01-30 05:41:39
ph88: if you're printing ("hello ", "world") as "hello world", aren't you throwing away the information that your data was in a tuple?
quchen 2017-01-30 05:42:22
lyxia: That's the difference between a prettyprinter and a serialization library.
ph88 2017-01-30 05:42:23
lyxia, yes i throw away the structure i build. I go from source code to syntax tree, and when i go back to source code i loose of course the tree structure and everything becomes flat text again
infandum 2017-01-30 05:42:27
I'm getting "Failed to load interface for 'Gtk2HsSetup'" even AFTER installing gtk2hs-buildtools (trying to install cairo). Did something change?
Vq 2017-01-30 05:42:45
shapr: I work on a C# project as well and have to fight with msbuild, one of the worst build systems I've seen.
nogid 2017-01-30 05:42:46
for example it's a myth that in C++ you end up with memory leaks. You have all the tools to set up life-times of dynamically allocated memory in a declarative way (unique_ptr, shared_ptr, memory arenas)
infandum 2017-01-30 05:42:53
stack resolver is lts-7.18
Cale 2017-01-30 05:42:54
nogid: I'm just going to assume that you haven't done a large amount of programming in Haskell yet ;)
nogid 2017-01-30 05:43:03
Cale: nope I haven't
Cale 2017-01-30 05:43:30
nogid: The difference in terms of how many more of your bugs get caught at compile time is ridiculously large.
nogid 2017-01-30 05:43:43
Cale: but you have to consider that there are many different styles possible in C++. If someone is writing C-in-C++, of course the compiler is going to be much less helpful in catching mistakes
ph88 2017-01-30 05:43:43
lyxia, data Foo = F String String ---> String ++ String data Foo = F String, String ---> String ++ String data Foo = F [String] --> mapM_ putStrLn [String]
Cale 2017-01-30 05:44:13
To the extent that I regularly do refactors against a large codebase that touch hundreds of lines of code, and have everything work perfectly the moment it compiles again.
ph88 2017-01-30 05:44:44
quchen, you think i should use a serialization library? i thought a pretty printer could do the same and also would be very handy later in case i want to apply formatting (which is not a requirement right now, but will be later)
Cale 2017-01-30 05:44:52
Including refactoring other people's code that I don't even understand
Cale 2017-01-30 05:45:05
(because I don't have time to understand it)