ph88 2017-02-02 10:45:43
i put this TH code in a separate file so it would work properly https://paste.fedoraproject.org/543230/71873148/ now i want to use a class in this file but also in the Main.hs file, should i put the class in the Main.hs file and then import main module or what would be the best approach here ?
glguy 2017-02-02 10:46:26
ph88: You can put the class in a third file that both Main and MarkArb import
glguy 2017-02-02 10:46:33
It's files all the way down
ertes 2017-02-02 10:46:38
is there a way to map over the value of a Weak? it's fine if IO is required for that
taktoa 2017-02-02 10:47:15
anyone know if there's a canonical typeclass that's like Alternative but doesn't have `empty`? Semigroup : Monoid :: ? : Alternative
ertes 2017-02-02 10:47:30
taktoa: the Alt type class from the semigroupoids package
ertes 2017-02-02 10:47:45
taktoa: but it also doesn't depend on Applicative
glguy 2017-02-02 10:47:59
ertes: You could make a new Weak with the mapped value
glguy 2017-02-02 10:48:24
ertes: suppose you were using 'mkWeakPair' you could dereference the weak pair, map over the "value" and make a new Weak pair
taktoa 2017-02-02 10:48:25
ertes: thanks, I had a feeling it would be in semigroupoids
ertes 2017-02-02 10:48:52
glguy: doesn't that lose the reference to the original key?
glguy 2017-02-02 10:48:55
ertes: The pairness comes in so that you have access to the key again
glguy 2017-02-02 10:49:04
mkWeakPair :: k -> v -> Maybe (IO ()) -> IO (Weak (k, v))
ertes 2017-02-02 10:49:32
glguy: actual problem: i need a Weak that refers to an IORef, but has a different value from the IORef itself
ertes 2017-02-02 10:50:04
mkWeakIORef only gives me a Weak (IORef a)
ertes 2017-02-02 10:50:36
glguy: in other words i never get hold of the key itself… it's the underlying MutVar# of the IORef
glguy 2017-02-02 10:50:47
ertes: I think you're just going to have to inline mkWeakIORef and modify it to have the behavior you want
ertes 2017-02-02 10:51:13
yeah, sounds like the only option… thanks
glguy 2017-02-02 10:51:16
I don't remember that existing
Tuplanolla 2017-02-02 11:05:38
Is there some sort of a guideline for abbreviating constructors or accessors?
iostream 2017-02-02 11:06:02
Hello. I got into an argument earlier today, and I just wanted to clear up my understanding. The question should not be understood specifically to haskell, but in a broader sense of pure functional languages: To what extend does the type of List guarantee/imply that (a) it is a finite structure and (b) it is non-circular?
zomg 2017-02-02 11:06:13
Tuplanolla: I seem to recall seeing Ctor as one for constructor
Tuplanolla 2017-02-02 11:06:14
I really don't feel like writing `GeometricAutomorphismGroup` and the other extreme `GAG` isn't much better.
zomg 2017-02-02 11:06:26
ohh that's what you meant :P
geekosaur 2017-02-02 11:10:01
iostream, it doesn't guarantee either one
iostream 2017-02-02 11:11:39
geekosaur: Could you comment a bit on your line of reasoning?
Tuplanolla 2017-02-02 11:12:45
> let xs = 'H' : 'A' : xs in xs -- Here's an infinite circular list for you, iostream.
lambdabot 2017-02-02 11:12:47
"HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH...
Quintasan 2017-02-02 11:13:17
Someone beat me to it :(
hsk3 2017-02-02 11:13:28
Is it possible to add functions to existing typeclasses? (Analogous to extending a protocol in Swift)
glguy 2017-02-02 11:13:58
hsk3: No
hsk3 2017-02-02 11:14:07
Thanks good to know.
Jinixt 2017-02-02 11:14:21
what's the best parser-combinator lib if I want good error messages?
Jinixt 2017-02-02 11:14:24
performance is less important
Jinixt 2017-02-02 11:14:38
errors in the parsing, that is
glguy 2017-02-02 11:14:52
hsk3: You can construct a definition in terms of the methods of a class, and that definition will work for all the same types that have instances, however
glguy 2017-02-02 11:15:00
hsk3: No need to attach it to the typeclass itself
glguy 2017-02-02 11:15:21
hsk3: Of course it wouldn't make sense to add new methods to an existing typeclass. All the existing instances would become incomplete
geekosaur 2017-02-02 11:15:28
Jinixt, probably trifecta or megaparsec
iostream 2017-02-02 11:16:07
Okay, I see that. Then, how am I supposed to write .. say a function that computes the length of a (finite, non-circular) list and is guaranteed to terminate?
hsk3 2017-02-02 11:16:15
yeah
Jinixt 2017-02-02 11:16:29
any philosophical differences between the two?
jophish 2017-02-02 11:19:00
Jinixt: might want to investigate the earley parser too
geekosaur 2017-02-02 11:20:58
I'd say they're both conceptually similar (enough so that the parsers package can wrap both)
jophish 2017-02-02 11:23:42
Jinixt: https://github.com/purescript/purescript/issues/1488#issuecomment-200873139
ertes 2017-02-02 11:26:46
iostream: you can't… a length function for lists is inherently non-total
erisco 2017-02-02 11:27:53
such is the topic of recursive data
ertes 2017-02-02 11:28:06
iostream: (in haskell)
erisco 2017-02-02 11:29:00
like, Vector
ertes 2017-02-02 11:29:09
iostream: languages with explicit support for the data/codata distinction and total functions will either require your list type to be data or reject any attempt to write a length function for it
ertes 2017-02-02 11:29:47
so you can only have infinite lists *or* a length function, but never both
hodapp 2017-02-02 11:30:24
what languages explicitly distinguish data and codata?
erisco 2017-02-02 11:30:26
and what is life without infinite lists
ertes 2017-02-02 11:30:35
hodapp: agda
iostream 2017-02-02 11:30:57
What about languages such as ML?
ertes 2017-02-02 11:31:10
MLs are strict, aren't they?
iostream 2017-02-02 11:31:29
So, would you say that in strict languages these properties can be assumed?
ertes 2017-02-02 11:31:42
well, you can't have infinite lists in those
iostream 2017-02-02 11:32:02
Yes, but why exactly?
ertes 2017-02-02 11:32:03
so 'length' is total, but you can still pass it a ⊥
Jinixt 2017-02-02 11:32:23
jophish: geekosaur: thanks
iostream 2017-02-02 11:32:36
Is it a property of the type system, of the semantics (eagerness), or both? Where exactly do you derive the property from
erisco 2017-02-02 11:33:09
there are kind classes?
erisco 2017-02-02 11:33:16
I've been left in the dust
ertes 2017-02-02 11:33:18
if you allow codata, it's a type system and semantics property… a total language has no semantics for general recursion, so it must reject it
ertes 2017-02-02 11:33:27
erisco: -XTypeInType
iostream 2017-02-02 11:34:58
ertes: What is codata, and what is its relevance here?
jophish 2017-02-02 11:35:26
np Jinixt, do let us know what you end up with!
EvanR 2017-02-02 11:36:30
iostream: codata is potentially infinite data, codata structures are defined by a program to generate more of the structure, which is guaranteed to progress
ertes 2017-02-02 11:36:36
iostream: codata is just data, unless you also have a termination checker: data cannot be infinite and recursion must use structurally smaller arguments… codata can be infinite, but recursion must always be productive
ertes 2017-02-02 11:37:03
'repeat' is a proper codata producer, while 'filter' is not
iostream 2017-02-02 11:37:49
Okay; that makes sense. So in this context, the question boils down to whether you have codata and a termination checker/totality?
iostream 2017-02-02 11:38:01
And lack of mutability ...
iostream 2017-02-02 11:38:36
So, in a strict, pure, total functional language you can write a length function that terminates
EvanR 2017-02-02 11:38:43
inductive data and coinductive codata are still things you can pretend about in your head, in haskell
ertes 2017-02-02 11:38:47
in fact you can't use recursion on codata, even if recursive arguments are structurally smaller… most notably you can't have foldr for a colist
Cale 2017-02-02 11:38:51
Well, mutability is an independent thing, but it's hard to do any termination checking in its presence.
ertes 2017-02-02 11:38:52
and you can't have unfoldr for a list
Cale 2017-02-02 11:40:26
Note that while termination checking will guarantee that eager evaluation of data will terminate, that doesn't always mean it's always a good idea to use eager evaluation on data in that case.
ertes 2017-02-02 11:40:28
more generally: you can only have catamorphisms for structures and anamorphisms for costructures, unless the structure/costructure is flat
Cale 2017-02-02 11:40:51
Lazy evaluation can still be critically advantageous, even in a setting where everything is guaranteed to finish.
dolio 2017-02-02 11:41:26
You can write a length function that terminates in Haskell if you use `data L a = N | C a !(L a)`.
dolio 2017-02-02 11:41:45
Terminates except on already non-terminating inputs.
Cale 2017-02-02 11:41:59
This is primarily because large finite values are a reasonably decent approximation to infinity -- it's easy to produce provably finite lists which are actually quite useful if evaluated lazily, and which which nevertheless you'll never be able to finish computing.
Cale 2017-02-02 11:42:47
s/which which/which/
Cale 2017-02-02 11:42:48
lol
ertes 2017-02-02 11:43:04
s//which/ -- i see a monad there =P
Cale 2017-02-02 11:43:18
haha
EvanR 2017-02-02 11:43:20
/usr/bin/which
Cale 2017-02-02 11:43:40
which: shell built-in command
EvanR 2017-02-02 11:43:54
black magic