merijn 2017-02-08 02:45:26
Well, no, because the Enum for String is unlikely to be useful :p
phadej 2017-02-08 02:46:30
pairs of values: you wan't have lawful Iso (it would be a Prism)
merijn 2017-02-08 02:47:15
oh, I suppose
merijn 2017-02-08 02:47:39
I dunno, I just don't wanna write the exact same case twice with the left/right side of -> swapped
phadej 2017-02-08 02:48:20
merijn: I write something like: https://github.com/futurice/haskell-mega-repo/blob/3217f7bbfa2acbf57442f14fe4c544818c3b7c3d/checklist-app/src/Futurice/App/Checklist/Types/Location.hs#L36-L50
phadej 2017-02-08 02:49:24
I don't know better solution
merijn 2017-02-08 02:51:34
phadej: oh, that's already better
BernhardPosselt 2017-02-08 03:15:35
regarding Monoids: you define them per type correct? arent there sometimes more than one operation per type?
BernhardPosselt 2017-02-08 03:15:41
e.g. ints have sum and product
ketil_ 2017-02-08 03:15:57
Hi! I'm trying to compile an executable with profiling, but of course there is a huge mess of libraries installed without profiling support. Is there a way to use a sandbox or whatever to get cabal to just download and install what's missing?
merijn 2017-02-08 03:16:00
BernhardPosselt: Correct, usually people use newtypes for that
merijn 2017-02-08 03:16:10
BernhardPosselt: For example, see Sum and Product in Data.Monoid
merijn 2017-02-08 03:16:27
> getSum . mconcat . map Sum $ [1..10]
lambdabot 2017-02-08 03:16:29
55
ketil_ 2017-02-08 03:16:34
Currently, it will complain about one library at a time that exists in the global directory (/usr/lib).
merijn 2017-02-08 03:16:38
> getProduct . mconcat . map Product $ [1..10]
dcoutts 2017-02-08 03:16:40
ketil_: yes you can use a sandbox or the "cabal new-build" beta-ui which handles this stuff much better
lambdabot 2017-02-08 03:16:41
3628800
ketil_ 2017-02-08 03:17:54
dcoutts, how? My cabal doesn't know about new-build. How can I get the sandbox to ignore globally insatlled stuff?
dcoutts 2017-02-08 03:18:54
ketil_: oh, the sandboxes do not ignore globally installed stuff, it works on the assumption that the only global things are what come with ghc or with your distro (which will usually install prof versions too, or at least can do)
dcoutts 2017-02-08 03:19:06
ketil_: the new-build ui is in version 1.24+
dcoutts 2017-02-08 03:19:15
or better, in cabal head, if you want to that that new ui
BernhardPosselt 2017-02-08 03:20:09
ok, so tl;dr: a monoid is just a very abstract interface to define operations on types that are assoc and have a neutral element and you need specific instances for using them :)
ketil_ 2017-02-08 03:20:39
Ngh. I fear /usr/lib is now a wild combination of stuff installed via cabal and via apt-get. So there's no way for me to clean it out safely, and no way to get cabal to ignore it..
ketil_ 2017-02-08 03:21:05
Seems like it is easiest to find a different machine with nothing installed, and use that as a physical sandbox... :-P
merijn 2017-02-08 03:21:08
BernhardPosselt: Usually there's an "obvious" default instance (such as concat for lists), but in cases of Sum/Product we usually define newtypes for the alternate behaviour
dcoutts 2017-02-08 03:21:13
ketil_: it should be /usr/local/lib for cabal and /usr/lib for apt-get
merijn 2017-02-08 03:21:24
BernhardPosselt: See also "Data.Monoid.Dual" which is the "flip mappend" monoid
ketil_ 2017-02-08 03:21:37
Hm. ghc-pkg only showed /usr/lib, no /usr/local/lib. Let me check again.
BernhardPosselt 2017-02-08 03:21:58
as for using the interface: you usually want a Monoid for parallel computations, right?
merijn 2017-02-08 03:22:30
Not particularly, they're useful for lots of things
BernhardPosselt 2017-02-08 03:22:40
what are other usecases?
BernhardPosselt 2017-02-08 03:23:14
(apart from being able to combine things :D)
Welkin 2017-02-08 03:23:50
monoids?
Welkin 2017-02-08 03:23:52
semigroups?
BernhardPosselt 2017-02-08 03:23:56
yes
merijn 2017-02-08 03:24:03
BernhardPosselt: I had a neat example yesterday, lemme see if it's logged
Welkin 2017-02-08 03:24:20
BernhardPosselt: monads are monoids, too
BernhardPosselt 2017-02-08 03:24:45
right, but thats not really helpful in understanding the usecase :D
merijn 2017-02-08 03:24:49
Not particularly helpful and not true
Welkin 2017-02-08 03:25:09
it's true, just not in haskell's typeclass system
merijn 2017-02-08 03:25:27
Welkin: It requires a monoid instance on the type inside the monad
Baughn 2017-02-08 03:25:35
*Applicative
Welkin 2017-02-08 03:25:49
merijn: how about monoids and finger trees?
Welkin 2017-02-08 03:26:08
http://apfelmus.nfshost.com/articles/monoid-fingertree.html
ketil_ 2017-02-08 03:26:19
dcoutts - /usr/local/lib only contains python, so my cabal is apparently misconfigured.
cocomo 2017-02-08 03:26:19
is it possible to traverse over a non-binary tree with tail recursion? because it seems like there are two sub-problem? 1. traversing siblings 2. traversing children..
merijn 2017-02-08 03:26:51
BernhardPosselt: See this example of using Monoid for multi-column sorting: http://www.irclogger.com/.haskell-beginnerS/2017-02-07#1486484972
dcoutts 2017-02-08 03:26:53
ketil_: or perhaps you didn't install things globally with cabal at all
dcoutts 2017-02-08 03:27:11
ketil_: afterall it's not the default, you have to explicitly use --global and sudo to do it
Welkin 2017-02-08 03:27:12
cocomo: write a fold for your tree datatype
merijn 2017-02-08 03:27:19
cocomo: 1) yes, it's possible 2) tail recursion in haskell is not as relevant as you might be thinking
BernhardPosselt 2017-02-08 03:27:20
merijn: thanks
Welkin 2017-02-08 03:27:25
Foldable/Traversable instance
ketil_ 2017-02-08 03:27:33
Oh yes, they have today's date. I apt-get remove'd all libghc*, so now it is only my own cruft (and what comes with ghc) left.
cocomo 2017-02-08 03:29:59
Welkin: thank you. merijn I am using a flavor of purescript, they emphasis on tail recursion.
merijn 2017-02-08 03:30:06
Is there a datatype to use for bounds on Int ranges? i.e. an upperbound that is either unknown or some specific value
Welkin 2017-02-08 03:30:08
a flavor?
Welkin 2017-02-08 03:30:12
I thought there is only one purescript
BernhardPosselt 2017-02-08 03:30:20
merijn: i see, Comparator.comparing in java which is lovely
cocomo 2017-02-08 03:30:31
sorry, mixed my thoughts there. I mean't purescript*
merijn 2017-02-08 03:30:45
cocomo: Ah, then I don't know, I have no clue how purescript compiles
merijn 2017-02-08 03:32:31
I could use "Maybe Int", but I think that compiles the wrong way...
Welkin 2017-02-08 03:33:23
merijn: what are you asking exactly?
cocomo 2017-02-08 03:33:26
merijn: it compiles to js and js call stack overflows if you don't do tail recursion. purescript compiles tail recursions to a loop.
Welkin 2017-02-08 03:33:50
cocomo: not in es6
Welkin 2017-02-08 03:34:01
oh, yeah I see
Welkin 2017-02-08 03:34:25
purescript should optimize that away though
merijn 2017-02-08 03:35:11
Welkin: I don't think what I want exists, I'll write out a quick implementation to show what I mean
cocomo 2017-02-08 03:35:25
i hear a js guru/standards committe member crockford douglas say tail recursion didn't make into the es6 standards
cocomo 2017-02-08 03:35:48
sorry I should've googled that before saying it. I am not sure.
Welkin 2017-02-08 03:36:04
BoundedInt bound value
Welkin 2017-02-08 03:36:05
?
Welkin 2017-02-08 03:36:11
something like that?
merijn 2017-02-08 03:36:46
Welkin: No, not a bounded int, but a type for computing with bounds
merijn 2017-02-08 03:37:30
Like
merijn 2017-02-08 03:37:33
data Min a = MinusInfinity | Min a
merijn 2017-02-08 03:37:33
data Max a = Max | MaxInfinity
tfc 2017-02-08 03:37:59
anyone experienced with conduit? i took a line of code from the tutorial and it doesn't work: (Inherited, src, ClosedStream, cph) <- streamingProcess (shell "cat")
tfc 2017-02-08 03:38:05
it tells me Ambiguous type variable 'stdout0' arising from a use of 'streamingProcess'
tfc 2017-02-08 03:38:12
am i missing something important here?
merijn 2017-02-08 03:39:05
tfc: It means stdout0 is some kinda typeclass polymorphic variable and GHC can't infer what you wanted it to be
tfc 2017-02-08 03:39:21
the error message tells me i could use instance [safe] OutputSink UseProvidedHandle
merijn 2017-02-08 03:39:30
What library is that from?
Welkin 2017-02-08 03:39:42
tfc: try copying the entire example instead of one line
tfc 2017-02-08 03:39:47
Data.Streaming.Process
merijn 2017-02-08 03:39:58
THat's a module, not a library
tfc 2017-02-08 03:40:13
ok, its a module from the conduit streaming lib
tfc 2017-02-08 03:40:39
Welkin: there is no code which defines that "src" before, which is why i don't understand it. it's that tutorial https://github.com/snoyberg/conduit/blob/master/PROCESS.md
merijn 2017-02-08 03:42:08
It's not from conduit, because Data.Conduit.Process does not exist in the conduit package
Welkin 2017-02-08 03:42:30
just copy the whole example
merijn 2017-02-08 03:42:46
tfc: Are you trying it in ghci?
tfc 2017-02-08 03:42:51
Welkin: i see. when i copy ALL code from the example, it does indeed work. but that is strange, because that var "src" is used _after_ that other line which had the problem
Welkin 2017-02-08 03:42:52
there can be ambiguity because there is not enough information to infer the types
tfc 2017-02-08 03:43:00
how does this work? this looks magic.
tfc 2017-02-08 03:43:10
is this kind of "lazy inference"?
Welkin 2017-02-08 03:43:11
you are not doing anything with the outputs from that action that you are matching on (src, cph)
merijn 2017-02-08 03:43:15
tfc: GHC inference is not bound by ordering so the use later is perfectly sane
Welkin 2017-02-08 03:43:16
but the code one line down uses them
tfc 2017-02-08 03:43:27
wow i was not aware of this.
tfc 2017-02-08 03:43:39
ok, thank you. that solves my problem and i think i understand.
merijn 2017-02-08 03:43:42
tfc: All inference is at compile time, so before code ever runs. So the order of execution is not relevant for type inference
merijn 2017-02-08 03:44:25
tfc: If you do it line by line ghc gets confused because it's polymorphic. In the full example the latter use lets GHC infer which of the possible options you actually wanted
tfc 2017-02-08 03:44:52
i thought that's not possible. :-D