Search Haskell Channel Logs

Wednesday, February 8, 2017

#haskell channel featuring bartavelle, fdfddf, lambdabot, Maxdamantus, Axman6, mutsig, and 12 others.

erisco 2017-02-07 22:45:29
I am not sure why to bother with the inductive proofs
bitonic 2017-02-07 22:49:15
flxw: yeah, I'd also seriously question whether you really need to build it. It's you're probably going to waste quite a bit of time building it if you're not familiar with the tooling.
fdfddf 2017-02-07 22:50:24
hi
shiona 2017-02-07 22:50:33
hello
halogenandtoast 2017-02-07 22:50:55
Is there a way to embed the json itself in an instance of parseJSON. Something like:
fdfddf 2017-02-07 22:50:55
i'm exciting
lpaste_ 2017-02-07 22:51:02
halogenandtoast pasted "Embed.hs" at http://lpaste.net/352220
halogenandtoast 2017-02-07 22:51:10
^^
erisco 2017-02-07 22:52:24
it would make sense to do this if we were not allowed multiple use sites of the same variable
erisco 2017-02-07 22:52:43
i.e. it cannot decide equality
bartavelle 2017-02-07 22:52:44
halogenandtoast, yes, but j has type Value, not Object
bartavelle 2017-02-07 22:52:52
v has type Object
erisco 2017-02-07 22:53:00
but the type system does have that capability, so
bartavelle 2017-02-07 22:53:09
which is just a type alias to HashMap Text Value
bartavelle 2017-02-07 22:53:25
also you'd need "pure v"
halogenandtoast 2017-02-07 22:53:38
Oh right
halogenandtoast 2017-02-07 22:54:09
Thanks erisco and bartavelle
bartavelle 2017-02-07 22:54:13
np
erisco 2017-02-07 22:54:19
I'll take all the credit
bartavelle 2017-02-07 22:54:24
;)
halogenandtoast 2017-02-07 22:54:37
Hey I appreciate anyone taking the time to try and help.
halogenandtoast 2017-02-07 22:55:16
You're not getting paid to help me so the fact that anyone does is an amazing testimate to the community
erisco 2017-02-07 22:55:26
I was just mumbling to myself mainly
bartavelle 2017-02-07 22:55:58
crazy guy that mumbles to himself is always welcome in an inclusive community
Profpatsch 2017-02-07 22:56:37
Argh, Spock & Persistent, how.
erisco 2017-02-07 22:57:02
:t Witness
lambdabot 2017-02-07 22:57:04
error: Data constructor not in scope: Witness
Axman6 2017-02-07 22:57:20
halogenandtoast: we're just a bunch of people who hate seeing other wrong on the internet and must correct them, we're just good at hiding it's for our own satisfaction ;)
erisco 2017-02-07 22:58:56
:t Refl
lambdabot 2017-02-07 22:58:57
forall k (a :: k). a :~: a
erisco 2017-02-07 22:59:17
I mean really that is it right there, the only proof you need for all type equality
Profpatsch 2017-02-07 22:59:26
instance MonadIO a => MonadBaseControl IO a
Profpatsch 2017-02-07 22:59:36
hwhy not?
jita 2017-02-07 22:59:41
Will learning clojure first before learning haskell would help grasp the concept easier coming from python background ?
Profpatsch 2017-02-07 22:59:52
jita: That was the route I took.
halogenandtoast 2017-02-07 22:59:55
Axman6: Good enough for me.
Profpatsch 2017-02-07 23:00:05
It's easier with type signatures, believe me.
jita 2017-02-07 23:00:38
Profpatsch, would you recommend doing it ? Do u still use clojure ?
Profpatsch 2017-02-07 23:00:52
jita: No, I'd recommend a typed language.
erisco 2017-02-07 23:00:58
it is definitely a strange matter… not helped by the noise of Haskell
Axman6 2017-02-07 23:01:02
jita: clojure may feel more like python, but if you want to learn Haskell, learn Haskell. they're quire different. Being functional languages is less important than the stront vs weak type systems
Axman6 2017-02-07 23:01:08
strong*
Profpatsch 2017-02-07 23:01:14
Having type signatures eases grasping higher-order functions.
jita 2017-02-07 23:01:27
Axman6, is clojure weakly typed language ?
Profpatsch 2017-02-07 23:01:40
jita: Yes, it's a lips
Profpatsch 2017-02-07 23:01:42
*lisp
Axman6 2017-02-07 23:01:53
as far as I know it is, I haven't used it. most lisps are
erisco 2017-02-07 23:02:15
it has no syntax, you know
liste 2017-02-07 23:02:28
does "weakly typed" here mean "dynamically typed" or "having implicit conversions" ?
Profpatsch 2017-02-07 23:02:37
With the added negative point of throwing Java errors instead of more descriptive ones.
raichoo 2017-02-07 23:02:44
liste: I was wondering the same.
Axman6 2017-02-07 23:02:54
or, it is only syntax 🤔
Profpatsch 2017-02-07 23:02:56
unityped. :)
Axman6 2017-02-07 23:03:43
liste: i'm probably being too imprecise with me terminology, dynamically typed is probably more appropriate
erisco 2017-02-07 23:04:25
'arr with me terminology
halogenandtoast 2017-02-07 23:04:35
... persisting JSON to the database is unfun. I wish persistent supported the json time natively.
liste 2017-02-07 23:04:47
Axman6: unityped is even more appropriate (:
bartavelle 2017-02-07 23:05:00
halogenandtoast, you can newtype it
erisco 2017-02-07 23:05:13
implicit conversions are irrelevant
halogenandtoast 2017-02-07 23:05:30
bartavelle: and derive it automagically?
erisco 2017-02-07 23:05:32
with dynamic typing you statically have one type and at runtime there are many types
erisco 2017-02-07 23:05:51
as the program executes it does some type checking and that is when errors will be discovered
halogenandtoast 2017-02-07 23:06:11
I actually don't think I understand newtype very well (it seems the same as data to me, but I haven't figured out when to use it).
bartavelle 2017-02-07 23:06:14
halogenandtoast, you'll just have to write the newtype once, give it the proper instances, and then you'll be able to write "foo (JSON (M.Map Text Int))"
bartavelle 2017-02-07 23:06:18
in the quasiquoter
erisco 2017-02-07 23:06:18
the issue with just one type is that statically just about everything works
bartavelle 2017-02-07 23:06:31
halogenandtoast, ok I'll bring a paste, gimme a second
halogenandtoast 2017-02-07 23:07:11
bartavelle: Quasiquoter is a word I've seen thrown around a lot lately, that's just what TemplateHaskell uses right?
bartavelle 2017-02-07 23:07:36
it's related, but QQ is when you have [stuff| like that]
bartavelle 2017-02-07 23:07:39
err
bartavelle 2017-02-07 23:07:47
[stuff| like that|]
bartavelle 2017-02-07 23:07:54
like your probably define your model
Maxdamantus 2017-02-07 23:07:57
`newtype` is pretty much just a restricted form of `data` with some funny semantics around bottom values.
erisco 2017-02-07 23:08:55
if you have one constructor and one field use newtype. If you think you have one field but are using a tuple then you're doing it wrong. Otherwise use data
Maxdamantus 2017-02-07 23:08:58
particularly, that a value will always destructure without requiring any reduction.
bartavelle 2017-02-07 23:09:03
halogenandtoast, I have this http://lpaste.net/8671642603889885184 it's a bit more complicated than what you'd need, because I introduced a VFromJSON typeclass that tries to decode several versions of the same structure
erisco 2017-02-07 23:09:20
that's how you decide without knowing what it is :P
bartavelle 2017-02-07 23:09:33
halogenandtoast, once you have that, you can declare column types like that "col (PGJS your type here)"
halogenandtoast 2017-02-07 23:10:12
bartavelle: did you summon this from the nether or were you already doing this somewhere?
halogenandtoast 2017-02-07 23:10:19
I hope the later or you're a wizard.
erisco 2017-02-07 23:10:22
I will say it can make some sense to newtype tuples but don't have a tuple just for the sake of newtype
bartavelle 2017-02-07 23:10:24
halogenandtoast, that's a copypasta :)
halogenandtoast 2017-02-07 23:10:48
okay, expectations returned to normal.
erisco 2017-02-07 23:11:44
similarly if you think you have one constructor but you're using Either that is the same idea
halogenandtoast 2017-02-07 23:12:38
erisco: I guess that helps me understand newtype a little.
bartavelle 2017-02-07 23:12:53
the main point of newtype, besides performance (which is often not relevant), is that you can wrap something you already know, derive all type classes instances you require (with GeneralizedNewtypeDeriving), and add/change the instances you need
bartavelle 2017-02-07 23:13:12
for example you could write a HashMap wrapper where the monoid instance is "Monoid a => Monoid (MyMap k a)"
bartavelle 2017-02-07 23:13:32
to change the behaviour of the current Monoid instance for HashMap
bartavelle 2017-02-07 23:14:04
halogenandtoast, oh I forget to most important part :)
Axman6 2017-02-07 23:14:16
it also adds type safety in cases where one type might be used ambiguously, like turning foo :: Text -> Text -> Text -> IO () into foo :: URL -> Port -> Content -> IO ()
bartavelle 2017-02-07 23:14:36
halogenandtoast, http://lpaste.net/8671642603889885184
bartavelle 2017-02-07 23:14:41
it has the newtype on top
erisco 2017-02-07 23:15:08
that's adding semantics, not safety, it is safe either way :) but I know what you mean
halogenandtoast 2017-02-07 23:16:01
bartavelle: unfortunately I have a no cargo-culting policy so it will probably take me some time to grok this.
halogenandtoast 2017-02-07 23:16:29
for instance I assume iso has something to do with isomorphs, but I haven't used them at all yet.
halogenandtoast 2017-02-07 23:16:48
and there's lots of other lens stuff in here (I've just started learning/using lenses)
bartavelle 2017-02-07 23:16:57
halogenandtoast, yah there is a ton of distracting stuff in here
bartavelle 2017-02-07 23:17:02
gimme a sec I'll write a simpler version
erisco 2017-02-07 23:17:13
if you always use data instead of newtype the worst that will happen is you'll spend some extra time deriving instances
erisco 2017-02-07 23:17:20
so I wouldn't sweat it
bitonic 2017-02-07 23:19:46
Well the other thing that would happen is that you're adding a level of indirection for your data
bitonic 2017-02-07 23:20:06
The runtime behavior of `newtype A = A Int` and `data A = A Int` is different
erisco 2017-02-07 23:20:21
imperceptible
bitonic 2017-02-07 23:20:52
erisco: what do you mean?
erisco 2017-02-07 23:21:59
in the average use the difference is negligible
bitonic 2017-02-07 23:22:25
erisco: not really, they have different behavior, you need to be aware of it
erisco 2017-02-07 23:22:46
the performance behaviour? no not really, you don't
phadej 2017-02-07 23:22:54
it is
phadej 2017-02-07 23:23:14
newtype wrapping and unwrapping is (mostly) free
Axman6 2017-02-07 23:23:21
free*
phadej 2017-02-07 23:23:23
with data it always cost something
erisco 2017-02-07 23:23:29
the semantics? well it could come up, but isn't so likely
erisco 2017-02-07 23:23:40
I'm not saying never learn newtype. I am saying it is not important
Axman6 2017-02-07 23:23:44
the whole type safe coercions fraqmework exists because it's not as free as it should be
phadej 2017-02-07 23:24:10
Axman6: yeah, but not using it isn't trying to solve at all
mutsig 2017-02-07 23:25:01
how "unfree" are newtypes? I always imagined that they were pretty much entierly free with ghc.
erisco 2017-02-07 23:25:15
learn it around the time you're also learning about unboxed data and ST
phadej 2017-02-07 23:25:53
erisco: well, if you do newtype PersonName = PersonName Text, it's imho good to learn to use newtype from beginning
erisco 2017-02-07 23:26:27
I disagree because it is frivolous complication for no perceivable benefit in the average use case
erisco 2017-02-07 23:27:50
it is a Haskellism that goes nowhere
bartavelle 2017-02-07 23:27:55
erisco, newtypes come before that, when you need to override / add type classes instances for types you do not own
erisco 2017-02-07 23:28:17
you eventually wonder how to bump up your performance or how to have multiple class instances and you learn about newtype
bartavelle 2017-02-07 23:28:24
I agree that the performance edge does not matter usually
erisco 2017-02-07 23:28:24
then that's it
phadej 2017-02-07 23:28:53
bartavelle: having million of ints or million of data WrappedInt Int = WrappedInt Int matters
erisco 2017-02-07 23:29:05
but you can still have multiple class instances just using data, so it still isn't critical
bartavelle 2017-02-07 23:29:36
erisco, you loose GeneralizedNewtypeDeriving, so it becomes extremely tedious
erisco 2017-02-07 23:29:55
extremely? we have different notions of extremely :P
phadej 2017-02-07 23:29:57
bartavelle: the pointer indirection is both cpu and memory hit
bartavelle 2017-02-07 23:30:34
phadej, certainly, but I am not convinced this is a common use case
phadej 2017-02-07 23:30:53
bartavelle: when `newtyping` domain-less `Int`s, it is
bartavelle 2017-02-07 23:30:58
erisco, tediousness becomes extreme really fast for me :)
bartavelle 2017-02-07 23:31:32
yeah, I mean, newtypes are useful and commonly used, I just don't think the performance advantage is very useful for most use cases
bartavelle 2017-02-07 23:31:41
obviously, that's just my very limited experience
roundhouse 2017-02-07 23:31:48
hi guys, I have a question about module layout. I'm trying to keep all types of a certain area in a "Types.hs" module. Unfortunately this makes it impossible to hide constructors, since I have to write those in different modules. What is your approach to solve this?
bartavelle 2017-02-07 23:32:11
adding meaning to the types and the type class stuff seem much more useful to me on a daily basis
bartavelle 2017-02-07 23:32:25
for when I need efficient storage I usually reach for unboxed vectors ...
bartavelle 2017-02-07 23:33:16
roundhouse, rename your module Internal.Types and don't hide the constructors ;)
bartavelle 2017-02-07 23:34:02
(I don't think I really understood the question, that was just a quip)
erisco 2017-02-07 23:34:12
if you want abstract data then put it in its own module
roundhouse 2017-02-07 23:34:16
bartavelle, :)
merijn 2017-02-07 23:34:51
roundhouse: Don't export the Types module from cabal and only reexport the types and not constructors
erisco 2017-02-07 23:34:56
that is a valid solution too. Many packages have an Internal module which is understood to be breaking on any version change
merijn 2017-02-07 23:35:09
roundhouse: Not all modules in your package are accessible to users of your package
bartavelle 2017-02-07 23:35:48
roundhouse, erisco : by all means, it's nicer to export everything in "Internal" modules, as you never know when someone will need to tinker a bit ...
roundhouse 2017-02-07 23:35:51
Ah I understand, so by hiding the module Types
merijn 2017-02-07 23:36:49
roundhouse: You'll probably want to re-export the types without constructors, though
roundhouse 2017-02-07 23:37:08
yeah, that makes sense
erisco 2017-02-07 23:37:33
yes. I'd rather be allowed to shoot myself in the foot with a Colt .45 than be safe with only a Nerf blaster
bitonic 2017-02-07 23:43:37
erisco: it's not just performance. `A (error "TODO")` behaves very differently depending on whether `A` is a data constructor or a newtype constructor
bitonic 2017-02-07 23:44:01
And the performance _does_ matter
bitonic 2017-02-07 23:44:08
Boxed types can be a huge drag on performance