Search Haskell Channel Logs

Tuesday, March 7, 2017

#haskell channel featuring roundhouse, angerman, lambdabot, osa1, jle`, Squarism,

osa1 2017-03-06 23:45:54
Akii: yeah like that function. I need a version of it that takes the parser as argument
jle` 2017-03-07 00:09:18
yes, if Data.Map was given a comparing function instead, then things would break
osa1 2017-03-07 00:09:26
things worse for CSV instances btw, because even the simplest types like Bool don't have a canonical representation
jle` 2017-03-07 00:09:41
because you have to guaruntee that *every* time someone uses a given Map, you have to use the same comparing function as the one it was created with
osa1 2017-03-07 00:09:47
jle`: not if you use the same function for insertion and lookup
jle` 2017-03-07 00:10:01
yes, you have to give the same function every time
osa1 2017-03-07 00:10:05
jle`: right. I'm willing to do that for CSV/JSON instances.
jle` 2017-03-07 00:10:27
so for JSON, you have to guaruntee that the same decoding parmaeter is used every time you work with it
jle` 2017-03-07 00:10:53
requiring people to pass it in at every single usage site is a sure-fire way to get a bug
osa1 2017-03-07 00:11:09
at least provide both versions of functions then
osa1 2017-03-07 00:11:22
I don't want to maintain this mess of newtypes
jle` 2017-03-07 00:11:40
like if you required people to pass in a comparator function every time you used insert/lookup for Data.Map is a really really fast way to get corrupted maps
jle` 2017-03-07 00:11:57
hopelessly corrupted maps would be inevitable
osa1 2017-03-07 00:12:23
I'm not talking about Ord or Eq or maps
jle` 2017-03-07 00:14:08
especially talking about situations where you use multiple modules and multiple executables all working polymorphically with json instances, if you require people to pass in a parser every time, it's an easy way to get data corruption
tdammers 2017-03-07 00:14:12
IMO the most whopping advantage of ToJSON / FromJSON being typeclasses is that you can write generic instances for higher-kinded types without dragging explicit encoders along
tdammers 2017-03-07 00:14:40
pretty much exactly that
osa1 2017-03-07 00:14:46
jle`: it's not the same situation at all. I can have multiple JSON providers that use different formats for the same thing.
tdammers 2017-03-07 00:15:01
osa1: you can still do that, just not through ToJSON / FromJSON
tdammers 2017-03-07 00:15:11
osa1: but you can still provide alternative ser/der explicitly
osa1 2017-03-07 00:15:17
tdammers: not easily. I need newtypes
tdammers 2017-03-07 00:15:34
osa1: not if you bypass the JSON typeclasses
osa1 2017-03-07 00:16:03
it's still a lot harder. like I said above many times, functions like .: need typeclasses
jle` 2017-03-07 00:16:05
osa1: you can have multiple ORd instances for types too. but the important thing is that you always use the same instance for a given Map value. and that you always use the same serializer for a given data channel
jle` 2017-03-07 00:16:56
you might have more than one way to serialize something, but the site of serialization and the site of deserialization have to agree on which one to use
jle` 2017-03-07 00:17:15
(like the site of insertion and the site of lookup have to agree on which comparator method to use)
osa1 2017-03-07 00:17:21
btw in languages like OCaml people solve this problem by parameterizing modules with Eq/Ord providers. different instances then get different types (or something like that, I'm not an expert)
osa1 2017-03-07 00:18:21
so lookup is attached to the map. you can only use that lookup function
osa1 2017-03-07 00:18:49
which uses the Ord/Eq etc. provided on initialization
osa1 2017-03-07 00:19:16
anyway
Squarism 2017-03-07 00:19:19
Using different API's ive come to juggle between Data.Text, Data.String, Data.ByteString. But its getting tedious. Is there any of them that "can go"
osa1 2017-03-07 00:19:44
I started to think that most typeclasses suck (and so do APIs that rely on typeclasses heavily)
Squarism 2017-03-07 00:20:07
(..and forgot to mention - the Lazy variants too)
jle` 2017-03-07 00:20:07
it is true that most typeclasses suck
jle` 2017-03-07 00:20:07
it's easier to write a bad typeclass than a good one
liste 2017-03-07 00:20:07
Squarism: Data.String
jle` 2017-03-07 00:20:07
but typeclasses have their specific and narrow set of benefits/use cases
Squarism 2017-03-07 00:20:14
liste, oh ok
liste 2017-03-07 00:20:30
Squarism: it usually has bad performance
jle` 2017-03-07 00:20:35
s/typeclasses have their/the idea of a typeclass has its
liste 2017-03-07 00:20:51
Squarism: Data.Text for text, Data.ByteString for binary data :)
Squarism 2017-03-07 00:21:02
ok!
tdammers 2017-03-07 00:21:06
you could probably get pretty close with -XImplicitParameters
jle` 2017-03-07 00:22:35
Squarism: i've seen libraries like this one https://hackage.haskell.org/package/string-conversions-0.4.0.1/docs/Data-String-Conversions.html
jle` 2017-03-07 00:22:46
but i'm not sure how good of an idea they are
tdammers 2017-03-07 00:22:48
then you could write something like: let ?toJSON = myCustomSerializer in serveJSON someSerializableValue
angerman 2017-03-07 00:22:54
anyone got some avx exercising code handy?
tdammers 2017-03-07 00:23:10
dynamic binding is ugly though IMO
Squarism 2017-03-07 00:25:15
I confess on beeing lazy in digging deeper into strings. Performance isnt my biggest concern. So i guess its written for people like me
jle` 2017-03-07 00:44:07
it looks similar to List
tdammers 2017-03-07 00:44:07
kind of, it seems
tdammers 2017-03-07 00:44:18
but not quite
tdammers 2017-03-07 00:44:30
initialize() is roughly return, and call() is roughly bind
jle` 2017-03-07 00:44:32
and list is indeed a monad, if that counts
tdammers 2017-03-07 00:44:50
however,
tdammers 2017-03-07 00:44:53
:t (>>=)
lambdabot 2017-03-07 00:44:56
Monad m => m a -> (a -> m b) -> m b
tdammers 2017-03-07 00:45:31
whereas call() is closer to :: m a -> a -> m a
tdammers 2017-03-07 00:47:27
m being GuessWhatThisIs, and m a being an instance of that class
roundhouse 2017-03-07 00:49:00
hi, if I have a typeclass with a parametric type family, "class A a where; data A a :: *" and I want to instansiate this class for a type "data B b = { ... }" I'd like to specify the type "data A a = b" but I get an error "Not a dataconstructor 'b'". Any ideas how I can do this?