Search Haskell Channel Logs

Friday, February 24, 2017

#haskell channel featuring robertkennedy, glguy, Aku, rgrinberg, geekosaur, lambdabot, and 7 others.

Welkin 2017-02-24 16:45:34
`f c = a . b $ c` becomes `f = a . b`
Cooler 2017-02-24 16:45:37
we are talking about f $ g not f $ g c
MarcelineVQ 2017-02-24 16:46:28
it typechecks because the `a` of `Num a` can be anything, so there can be an instance of Num (a -> a) there isn't one, but it's certainly possible
mekeor 2017-02-24 16:50:00
:t (+)
lambdabot 2017-02-24 16:50:07
Num a => a -> a -> a
mekeor 2017-02-24 16:50:53
:t ($)
Cooler 2017-02-24 16:50:55
does instance Num a => Num (a -> a) where (+) f g = \x -> (f x) + (g x) work?
lambdabot 2017-02-24 16:50:56
(a -> b) -> a -> b
MarcelineVQ 2017-02-24 16:52:31
you'd need to define all the required methods but give it a try
Cooler 2017-02-24 16:52:42
instance Num b => Num (a -> b) where (+) f g = \x -> (f x) + (g x)
Cooler 2017-02-24 16:52:58
same for all the others?
mekeor 2017-02-24 16:54:11
is ($) infixr or infixl?
MarcelineVQ 2017-02-24 16:54:20
mekeor: r
glguy 2017-02-24 16:54:23
mekeor: You can ask GHCi
MarcelineVQ 2017-02-24 16:54:24
Cooler: whatever makes sense, idk I've never needed to do this :> There's likely many different ways it could be done, otherwise the instance would probably exist
glguy 2017-02-24 16:54:26
:i $
glguy 2017-02-24 16:58:35
Cooler: consider https://hackage.haskell.org/package/NumInstances-1.4/docs/Data-NumInstances-Function.html
rgrinberg 2017-02-24 17:03:06
Is there anything an arrow based parsec can do that an applicative one can't? I'm reviewing this wiki page https://en.wikibooks.org/wiki/Haskell/Understanding_arrows#Static_and_dynamic_parsers and it seems like this whole static/dynamic thing can just as easily be done with applicative.
mekeor 2017-02-24 17:06:55
Cooler: it works http://sprunge.us/ATfM -- (((+1) $ (*2)) $ 3) == 7
Welkin 2017-02-24 17:08:27
sprunge? O.o
Welkin 2017-02-24 17:08:34
sounds like a porn site
c_wraith 2017-02-24 17:08:53
sprunge is from Futurama
Welkin 2017-02-24 17:09:24
> (==7) . (+1) . (*2) $ 3
lambdabot 2017-02-24 17:09:30
True
Welkin 2017-02-24 17:09:37
reads better
mekeor 2017-02-24 17:10:29
or -- 3 * 2 + 1
glguy 2017-02-24 17:14:36
or -- True
mekeor 2017-02-24 17:16:33
(||) True == const True
Welkin 2017-02-24 17:21:31
:t const id
lambdabot 2017-02-24 17:21:33
b -> a -> a
mekeor 2017-02-24 17:24:10
:t fix id
lambdabot 2017-02-24 17:24:10
a
mekeor 2017-02-24 17:24:17
:t fix (const id)
lambdabot 2017-02-24 17:24:20
a -> a
robertkennedy 2017-02-24 17:26:49
:t g f x y = [f x, f y]
lambdabot 2017-02-24 17:26:52
error:
lambdabot 2017-02-24 17:26:52
parse error on input '='
lambdabot 2017-02-24 17:26:52
Perhaps you need a 'let' in a 'do' block?
lpaste_ 2017-02-24 17:28:36
Aku revised "Getting parse error on |": "Getting parse error on |" at http://lpaste.net/6400890151794376704
centril 2017-02-24 17:28:38
I have: class PhaseIndex pi where phaseId :: f pi -> PhaseId , is it possible to generalize this to more parameters automatically w/o resorting to more classes?
Aku 2017-02-24 17:29:10
Can someone look at my code, I am getting parse error on |?
centril 2017-02-24 17:29:30
Do I have to use template-haskell for this ?
geekosaur 2017-02-24 17:29:58
Aku, "where" attaches to a declaration
geekosaur 2017-02-24 17:30:25
the where on line 6 ends the definition of clex, and the | on line 9 has nothing to attach to
Aku 2017-02-24 17:30:25
Can you elaborate?
Welkin 2017-02-24 17:30:50
Aku: line 12 should be `| otherwise = [c] : clex cs`
Aku 2017-02-24 17:31:02
ohhkay
geekosaur 2017-02-24 17:31:24
actually that's fine as is just not optimal :_
geekosaur 2017-02-24 17:31:26
:)
Aku 2017-02-24 17:31:37
welkin : If I do so then how do i include the case [] = []
Aku 2017-02-24 17:31:40
?
Welkin 2017-02-24 17:31:46
just leave it
geekosaur 2017-02-24 17:31:48
^
Aku 2017-02-24 17:31:57
okay
Aku 2017-02-24 17:32:20
geekosaur : can you post the working code for the same extract?
Welkin 2017-02-24 17:32:42
`where` clauses apply to the entire definition
Welkin 2017-02-24 17:32:55
and must go at the bottom
Aku 2017-02-24 17:33:14
Ohh..I get it
lpaste_ 2017-02-24 17:34:33
geekosaur annotated "Getting parse error on |" with "Getting parse error on | (annotation)" at http://lpaste.net/6400890151794376704#a352956
geekosaur 2017-02-24 17:34:54
although I would drop the rest_cs-s and just write the expression, since it's not worth abstracting it for reuse
Aku 2017-02-24 17:35:36
Thansk geekosaur
geekosaur 2017-02-24 17:36:09
(also note I did not test it and I am the typo king >.> )
Aku 2017-02-24 17:36:38
:D
Aku 2017-02-24 17:37:05
would it not be the case that otherwise won't allow the control to reach to '[]'?
Welkin 2017-02-24 17:38:56
no
Welkin 2017-02-24 17:39:15
functionName (a:as) = ...
Aku 2017-02-24 17:39:37
Hmm...I got it!
mekeor 2017-02-24 17:40:05
challenge: how many characters do you need for an expression evaluating to [1,2,3,1,2,3,1,2,3] ?
Welkin 2017-02-24 17:40:07
is just sugar for `functionName str = case str of (a:as) -> ...; [] -> `
Welkin 2017-02-24 17:40:30
it all gets turned into case expressions
Welkin 2017-02-24 17:40:34
even the | eguards
Welkin 2017-02-24 17:40:40
guards*
Welkin 2017-02-24 17:41:02
so you are branching down isolated paths as you match
Aku 2017-02-24 17:42:26
ohkay