Search Haskell Channel Logs

Thursday, February 2, 2017

#haskell channel featuring Koterpillar, Lokathor, erisco, Ptival, mniip, joneshf-laptop,

erisco 2017-02-02 15:45:43
I know their SOrd class is designed specifically to mimic Ord so they can lift functions with their TH jazz
erisco 2017-02-02 15:46:19
but there is seemingly no alternative
erisco 2017-02-02 15:46:56
I am not sure how :~: succeeds with being just a data type... I have to look more closely at that
erisco 2017-02-02 15:47:10
because the only obvious way to do :>: and :<: is as data families
erisco 2017-02-02 15:50:52
my suspicion is that deciding the equality is the exact same as deciding the type equality, and Haskell is already capable of that
erisco 2017-02-02 15:51:20
they are singletons and so if Haskell can solve the type equality for you then there is no reason to write the term equality
Lokathor 2017-02-02 15:52:09
you can't force the main thread to exit from a side thread while the main thread is running a foreign call
Lokathor 2017-02-02 15:52:17
i've written myself into a corner
erisco 2017-02-02 15:56:56
just keep finding more corners and you'll eventually round it out
joneshf-laptop 2017-02-02 15:59:44
I've got a "canonical" structure and a "view" of that structure with less info, e.g. `canon :: [(Tag, Text)]` vs `view :: Text` where `view = unwords $ snd <$> canon`. Is there a pattern or general approach that allows editing of the "view" and the changes reflected in the "canonical" structure?
joneshf-laptop 2017-02-02 16:00:14
It feels very optical, but I don't know how it might actually work.
erisco 2017-02-02 16:02:15
not quite as how you have it, but consider if you have editView :: (Text -> Text) -> [(Tag, Text)] -> [(Tag, Text)]
joneshf-laptop 2017-02-02 16:02:48
Oh, right. I'm totally up to change any of it.
erisco 2017-02-02 16:02:52
generally speaking you're getting into lenses which isn't in my expertise
erisco 2017-02-02 16:03:06
but there are advocates here happy to sell you on it
joneshf-laptop 2017-02-02 16:03:26
So how would `editView` work in this case?
erisco 2017-02-02 16:04:22
editView = fmap . fmap
joneshf-laptop 2017-02-02 16:05:36
I mean, what would you be passing to `editView`.
erisco 2017-02-02 16:05:36
you apply your editing function to every Text
erisco 2017-02-02 16:05:49
the editing function and then your source
joneshf-laptop 2017-02-02 16:06:01
What is the editing function?
erisco 2017-02-02 16:06:18
that is up to you. What do you want to do to your Text? anything that has type Text -> Text
joneshf-laptop 2017-02-02 16:07:08
I think I was a bit unclear with the example I gave :).
Lokathor 2017-02-02 16:08:05
erisco, the sensible answer is "stop using a blocking FFI call" :3
erisco 2017-02-02 16:08:35
Lokathor, will that work with GC?
joneshf-laptop 2017-02-02 16:09:06
erisco, So, let's say the "canonical" structure loos like: `[(Good, "Hello"), (Indifferent, "there"), (Indifferent, "you")]`. Then the "view" would look like `"Hello there you"`.
joneshf-laptop 2017-02-02 16:09:18
looks like*
mniip 2017-02-02 16:09:22
ohhhhhh
mniip 2017-02-02 16:09:49
&&& is just a mediating morphism for the binary product
erisco 2017-02-02 16:09:50
I see
erisco 2017-02-02 16:10:40
well, you first have to choose a different type for your view, because there is no way to reverse it
Lokathor 2017-02-02 16:10:43
erisco, I have no idea if it works with GC actually
erisco 2017-02-02 16:10:57
given a string of characters you cannot determine which substrings go where
mniip 2017-02-02 16:11:33
now where's the comediating morphism for the binary coproduct?
mniip 2017-02-02 16:12:03
Arrow a => a x z -> a y z -> a (Either x y) z
erisco 2017-02-02 16:12:15
so one representation is [Text]
erisco 2017-02-02 16:12:28
i.e. ["Hello", "there", "you"]
mniip 2017-02-02 16:12:33
huh that's ArrowChoice
mniip 2017-02-02 16:12:44
how did it happen that these are two different typeclasses
mniip 2017-02-02 16:13:10
more importantly, how did it happen that Arrow is a superclass of ArrowChoice
erisco 2017-02-02 16:13:29
but this gets a bit janky because if we map [Text] -> [Text] we're not sure the length is invariant
erisco 2017-02-02 16:13:47
and so we're not sure if we have a Text to give to every 2-tuple
erisco 2017-02-02 16:13:57
we might choose a policy for what happens with extra or missing Texts
Koterpillar 2017-02-02 16:13:58
erisco: that's why two fmaps
erisco 2017-02-02 16:14:33
well that will not work if you need to consider many of the elements at once, which I presume is the case
erisco 2017-02-02 16:14:41
otherwise we'd just look at them individually with fmap . fmap
erisco 2017-02-02 16:15:47
we can use lists with typed lengths but trust me that that isn't your desired first choice
joneshf-laptop 2017-02-02 16:16:00
Well, I guess what I'm wondering is less in the case of this specific example and more in the general case.
joneshf-laptop 2017-02-02 16:16:17
FWIW, my actual problem is almost exactly like the example I gave.
erisco 2017-02-02 16:16:58
if you only need to consider one Text at a time then fmap . fmap is the general solution
erisco 2017-02-02 16:17:15
for a more sophisticated and broader solution look to lenses
erisco 2017-02-02 16:19:22
if you have to consider multiple elements then I am not sure. It depends on the need
erisco 2017-02-02 16:19:30
you might use a left or right fold, for example
erisco 2017-02-02 16:20:02
you might use lists with typed length
erisco 2017-02-02 16:21:45
or lists without typed length if you want to cowboy it ;)
joneshf-laptop 2017-02-02 16:24:39
erisco, I don't think I'm explaining my thoughts well right now, but thanks for your insights!
erisco 2017-02-02 16:25:17
you might also succeed with both aggregating the Texts and using fmap . fmap
erisco 2017-02-02 16:25:42
so you can look at both all elements and the particular element at hand
erisco 2017-02-02 16:26:15
maybe the current element is indicated by an index into the aggregate
erisco 2017-02-02 16:27:28
joneshf-laptop, well we can go over your specific case and maybe extrapolate from that
erisco 2017-02-02 16:34:43
joneshf-laptop, you certainly cannot edit in the sense of mutate, that isn't part of Haskell
joneshf-laptop 2017-02-02 16:38:41
erisco, nah, I think tonight is not a good night for me to ask this question :). But, I thank you for your help.
erisco 2017-02-02 16:38:54
well here is another crazy idea
joneshf-laptop 2017-02-02 16:39:03
And for offering to go further.
Ptival 2017-02-02 16:39:18
given a multi-param-typeclass (Coerce a b), is is possible to create an alias (CoerceTo b a) such that one can use the family (CoerceTo TargetType)?
Ptival 2017-02-02 16:39:33
it seems Haskell insists on the alias being always fully-applied
erisco 2017-02-02 16:39:39
lets say we have Text -> Instr
erisco 2017-02-02 16:40:15
so we gather together the Texts to get our "Hello there you" and pass this to the editing function
erisco 2017-02-02 16:40:42
but the editing function does not return a new Text, it instead returns an instruction, or sequence of instructions, on how to manipulate the Text
erisco 2017-02-02 16:41:27
this is relevant because if the editing function just gave us a Text we do not necessarily know how to map back to canonical form
erisco 2017-02-02 16:41:37
but maybe with a particular instruction set we would
erisco 2017-02-02 16:43:40
then what you have is an eDSL
erisco 2017-02-02 16:43:48
the sledgehammer to all problems