Cooler 2017-02-23 06:49:25
?src foldMap
lambdabot 2017-02-23 06:49:25
Source not found. This mission is too important for me to allow you to jeopardize it.
Cooler 2017-02-23 06:50:11
"Thinking cap time. Write a filter function for Foldable types using foldMap."
Cooler 2017-02-23 06:50:17
how does this work?
Cooler 2017-02-23 06:51:27
filterF :: (Applicative f, Foldable f, Monoid (f a)) =>(a -> Bool) -> f a -> f a
pikajude 2017-02-23 06:52:02
is it supposed to be filter f . toList?
pikajude 2017-02-23 06:52:04
I don't understand
Cooler 2017-02-23 06:53:22
its supposed to act like filter i think
pikajude 2017-02-23 06:53:44
but you can't "filter" a binary tree
pikajude 2017-02-23 06:53:51
without rebuilding it
lyxia 2017-02-23 06:53:53
that's why there's a monoid
Cooler 2017-02-23 06:54:44
i am not sure how foldMap fits into this
pikajude 2017-02-23 06:55:48
but say you try to filter a Data.Tree.Tree
pikajude 2017-02-23 06:55:56
what do you return from foldMap
lyxia 2017-02-23 06:56:07
The type of trees is not (a priori) a monoid
pikajude 2017-02-23 06:56:21
well yeah, but it's a Foldable
pikajude 2017-02-23 06:56:31
so what's the correct behaviro
pikajude 2017-02-23 06:56:34
behavior
Cooler 2017-02-23 06:57:08
what does foldMap have to do with filter?
lambdafan 2017-02-23 06:57:25
I'm looking for this function isAlphaNum :: Text -> Bool
pikajude 2017-02-23 06:57:26
only the bit where it said "Use foldMap to implement a filter function"
pikajude 2017-02-23 06:57:28
heh
lambdafan 2017-02-23 06:57:35
but hoogle can't help me find it
pikajude 2017-02-23 06:57:45
lambdafan: Data.Char
monochrom 2017-02-23 06:57:48
@type filter
lambdabot 2017-02-23 06:57:50
(a -> Bool) -> [a] -> [a]
monochrom 2017-02-23 06:58:03
Is filter in Foldable?
lambdafan 2017-02-23 06:58:08
I thought Data.Char was for String only
pikajude 2017-02-23 06:58:37
lambdafan: sorry, i didn't see the signature
pikajude 2017-02-23 06:58:39
i just saw the name
pikajude 2017-02-23 06:58:58
what is that function supposed to do? test an entire Text to see if it's alphanumeric?
monochrom 2017-02-23 06:59:04
No, filter isn't concerned with Foldable. What is the type of your filter?
Cooler 2017-02-23 06:59:20
filterF :: (Applicative f, Foldable f, Monoid (f a)) =>(a -> Bool) -> f a -> f a
Cooler 2017-02-23 06:59:56
lyxia, do you know how?
pikajude 2017-02-23 07:00:00
so again, how do you implement this for Tree
monochrom 2017-02-23 07:00:13
I suspect "can't be done".
lambdafan 2017-02-23 07:00:18
pikajude: the Text will be a single character, I want to identify it as alphaNumeric (or not)
Cooler 2017-02-23 07:00:24
i thought he said trees aren't monoids
lyxia 2017-02-23 07:00:32
I suspect it can
pikajude 2017-02-23 07:00:37
lambdafan: why is it a Text if it's a single character?
pikajude 2017-02-23 07:00:53
Cooler: sorry about that, I didn't see the Monoid constraint
lambdafan 2017-02-23 07:01:00
pikaJude: because I need a way to encode unicode
pikajude 2017-02-23 07:01:08
lambdafan: text supports unicode already
pikajude 2017-02-23 07:01:17
you should be testing a Char if it's alphanumeric, not a Text
pikajude 2017-02-23 07:01:26
if you want to test a Text, you can use Data.Text.all isAlphaNum iirc
lambdafan 2017-02-23 07:01:56
I'm testing a single character at a time
pikajude 2017-02-23 07:02:17
ok, but given a Text, you should be able to operate on a single character at a time using the functions in Data.Text
pikajude 2017-02-23 07:02:20
can you paste code?
lyxia 2017-02-23 07:02:36
Cooler: the idea is that you can map elements to a singleton or empty container depending on the predicate, and mappend them together.
lambdafan 2017-02-23 07:02:43
pikajude sure
Cooler 2017-02-23 07:03:29
how?
pikajude 2017-02-23 07:03:59
foldMap (\ x -> if myPredicate x then ??? x else mempty)
Cooler 2017-02-23 07:04:21
filterF f xs = pure f <*> xs ......
Cooler 2017-02-23 07:05:13
i don't think foldMap takes a function
pikajude 2017-02-23 07:05:25
foldMap :: Monoid m => (a -> m) -> t a -> m
pikajude 2017-02-23 07:05:38
for pure, you need Applicative
lpaste_ 2017-02-23 07:05:47
lambdafan pasted "tokenizer" at http://lpaste.net/352915
Cooler 2017-02-23 07:06:07
pikajude, yeah look at the constraints
pikajude 2017-02-23 07:06:16
indeed
pikajude 2017-02-23 07:06:21
ok, that makes this much easier
pikajude 2017-02-23 07:06:35
it'd be foldMap (\ x -> if myPredicate x then pure x else mempty)
lambdafan 2017-02-23 07:06:56
pikajude: was that directed to me?
pikajude 2017-02-23 07:07:00
no
pikajude 2017-02-23 07:07:02
i'm reading your code
pikajude 2017-02-23 07:07:38
lambdafan: if you're operating on tokens, you can use `Data.Text.all isAlphaNum` as said before
pikajude 2017-02-23 07:08:56
lambdafan: although, those all look like single characters
Cooler 2017-02-23 07:09:34
pikajude, what does folding have to do with filtering?
pikajude 2017-02-23 07:09:53
Cooler: "Thinking cap time. Write a filter function for Foldable types using foldMap."
lambdafan 2017-02-23 07:10:16
pikajude: yes, I am operating on a single character at a time
Cooler 2017-02-23 07:10:22
pikajude, what does folding have to do with filtering?
pikajude 2017-02-23 07:10:32
no idea
Cooler 2017-02-23 07:11:15
i don't understand this it'd be foldMap (\ x -> if myPredicate x then pure x else mempty)
pikajude 2017-02-23 07:12:06
that expression has type (Applicative f, Monoid (f a), Foldable t) => t a -> f a
Cooler 2017-02-23 07:12:45
:t foldMap
lambdabot 2017-02-23 07:12:46
(Monoid m, Foldable t) => (a -> m) -> t a -> m
Cooler 2017-02-23 07:12:58
where did you get applicative from?
pikajude 2017-02-23 07:13:03
from pure
Cooler 2017-02-23 07:13:24
wat
pikajude 2017-02-23 07:13:38
pure :: Applicative f => a -> f a
Cooler 2017-02-23 07:13:55
theres no applicative constraint so how are you using pure?
lyxia 2017-02-23 07:14:30
Cooler: there is in the type of filterF
pikajude 2017-02-23 07:14:56
yeah, I don't think you can write it without using Applicative (or Pointed)
Cooler 2017-02-23 07:15:06
yeah but thats applying to f in f a
pikajude 2017-02-23 07:15:08
because neither Foldable nor Monoid gives you a -> f a
lyxia 2017-02-23 07:15:50
Cooler: t a -> f a is more general than t a -> t a
EvanR 2017-02-23 07:15:56
by filter you mean, take a foldable and output a list?
Cooler 2017-02-23 07:16:07
yes
pikajude 2017-02-23 07:16:08
EvanR, if i understand correctly, it's take a foldable and return the same foldable
Cooler 2017-02-23 07:16:10
no
Cooler 2017-02-23 07:16:15
not a list
EvanR 2017-02-23 07:16:17
foldable doesnt let you put the thing back together in any way
pikajude 2017-02-23 07:16:20
right
Cooler 2017-02-23 07:16:40
EvanR, exactly so what does foldMap have to do with this
Cooler 2017-02-23 07:16:43
?
pikajude 2017-02-23 07:16:43
so the best you can do is require that the input is also a Monoid and additionally provide some way to `wrap` a single value
pikajude 2017-02-23 07:17:00
foldMap just maps a function a -> m over every element of the Foldable and concatenates them
EvanR 2017-02-23 07:17:21
there is a typeclass based on traversible which has some attempt at laws that filter should follow
pikajude 2017-02-23 07:17:26
and the reason it's relevant here is because it's the only method of Foldable that lets you return a maybe-nothing result for an item
pikajude 2017-02-23 07:17:39
i.e. mempty
EvanR 2017-02-23 07:17:45
without that, its not clear what a filter should do with a non-list
pikajude 2017-02-23 07:17:54
right
EvanR 2017-02-23 07:19:13
singleton plus monoiding together doesnt sound like its any better than returning a list
pikajude 2017-02-23 07:19:32
fairly slow too
EvanR 2017-02-23 07:20:14
thats sort of the mentality behind "a type class for a generic container, you can get stuff out of it, and put stuff in it"
Cooler 2017-02-23 07:20:15
so whats the specialized type for foldMap here?
pikajude 2017-02-23 07:20:41
it depends on what kind of Foldable you're operating on
EvanR 2017-02-23 07:20:44
it sounds good in the board room but mathematically its not clear what its supposed to do
pikajude 2017-02-23 07:20:53
board room, lol
Cooler 2017-02-23 07:20:54
(a -> f a) -> f a -> f a?
EvanR 2017-02-23 07:21:25
it canna be done with foldable
pikajude 2017-02-23 07:21:33
EvanR: we're adding monoid and applicative
Cooler 2017-02-23 07:21:33
foldMap :: (Applicative f, Foldable f, Monoid (f a)) => (a -> f a) -> f a -> f a?
EvanR 2017-02-23 07:21:40
._.
pikajude 2017-02-23 07:21:43
Cooler: i think so
EvanR 2017-02-23 07:21:57
this is a different kind of foldMap ?
EvanR 2017-02-23 07:22:04
thats not a specialization
pikajude 2017-02-23 07:22:15
EvanR: no, we're specializing m to f a
johnw 2017-02-23 07:22:16
:t foldMap
lambdabot 2017-02-23 07:22:18
(Monoid m, Foldable t) => (a -> m) -> t a -> m
pikajude 2017-02-23 07:22:22
in the type of foldMap
pikajude 2017-02-23 07:22:26
or rather, `t a` in that case
ertes 2017-02-23 07:23:05
Recursive and Corecursive from recursion-schemes are the most generic container classes i know
EvanR 2017-02-23 07:23:07
so were answering a different question
ertes 2017-02-23 07:23:23
anything that is a fixed point could be an instance
EvanR 2017-02-23 07:23:52
ertes: i was just thinking, "someone will arrive at the conclusion that everything is a recursive algebraic type"
EvanR 2017-02-23 07:24:15
and go from there what container means
ertes 2017-02-23 07:24:18
EvanR: put my remark into the "acme" category =)
ertes 2017-02-23 07:24:53
amusing side note: that rules out Vector =)
EvanR 2017-02-23 07:25:00
it does get stuff done when you settle on "everything is X", but thats not necessarily generic
EvanR 2017-02-23 07:25:29
like when everything is one of the js types, and its dynamically typed. but its not generic
ertes 2017-02-23 07:26:35
or the classic: "everything is an object"
ertes 2017-02-23 07:26:42
whatever that actually means
EvanR 2017-02-23 07:26:55
Object the top class in java
bennofs1 2017-02-23 07:29:06
EvanR: and then there is 'int' and 'int[]' :)
dolio 2017-02-23 07:30:01
ertes: Vector is isomorphic to a recursive algebraic type.
nitrix 2017-02-23 07:30:30
It's worse when your language has theorically only a single type like PHP's Any and does dynamic classification to pretend it has a type system.
EvanR 2017-02-23 07:32:44
infinite vectors?
EvanR 2017-02-23 07:33:44
guess we can pretend its eager, inductive
pheaver_ 2017-02-23 07:33:59
I'm trying to get code coverage results from my application (I am using stack). I build with the ghc option -fhpc, and when I stack exec my application, it produces .mix files in a random dir under ./.hpc, but no .tix files.
pheaver_ 2017-02-23 07:35:16
It's not clear to me from the documentation or running the hpc program if a .tix file should be generated by my program or via some hpc command.
mbw 2017-02-23 07:36:00
Hello everyone. Are there any "fusion laws" regarding zipWith operations, i.e. something similar to fusing folds and maps, or two successive folds over the same data structure (banana split theorem)?
mbw 2017-02-23 07:36:37
For instance if I have scalarProd xs ys = sum . zipWith (*) xs $ ys.
chreekat 2017-02-23 07:36:42
pheaver_: have you looked at https://docs.haskellstack.org/en/stable/coverage/ ?
pheaver_ 2017-02-23 07:37:02
yes, i wasn't sure if it was applicable to me
pheaver_ 2017-02-23 07:37:14
my tests are blackbox tests in a separate standalone application
lyxia 2017-02-23 07:37:16
mbw: zipWith f (map g x) (map f y) = zipWith (\a b -> f (g a) (h b)) x y ?
pheaver_ 2017-02-23 07:37:23
i want code coverage in the application when i run my tests against it.
pheaver_ 2017-02-23 07:37:33
i tried the --coverage flag but didn't get any .hpc files
lyxia 2017-02-23 07:37:35
mbw: oops I meant to write map h y rather than map f y
lyxia 2017-02-23 07:38:01
mbw: map f (zipWith g x y) = zipWith (\a b -> f (g a b)) x y ?
lyxia 2017-02-23 07:38:24
mbw: is that the kind of thing you're looking for
chreekat 2017-02-23 07:39:09
pheaver_: ah, dunno, unless that 2nd bullet point in the doc applies to you
digitalmentat 2017-02-23 07:39:19
is there a better channel to ask questions about speeding up compilation of a custom GHC compiler?
mbw 2017-02-23 07:39:38
lyxia: Yes, something along those lines. While I don't have a specific optimization problem right now, I find the known "laws" quite helpful in understanding algorithms and converting from a quick and dirty haskell prototype to an imperative one for example. Is there any literature regarding zips?
pheaver_ 2017-02-23 07:40:04
yeah that bullet does not apply to me (and many others, i'm sure)
pheaver_ 2017-02-23 07:41:06
oh, a .mix file is generated when *compiling*
lyxia 2017-02-23 07:42:37
mbw: unfortunately I have no idea
lyxia 2017-02-23 07:43:32
mbw: the things I wrote are probably instances of the free theorem of the type of zipWith
lyxia 2017-02-23 07:43:52
mbw: Theorems for free! by Phil Wadler explains these.
mbw 2017-02-23 07:44:21
I think I looked into this paper and found it quite dense.
lyxia 2017-02-23 07:44:26
It is.
mbw 2017-02-23 07:44:29
:(