Search Haskell Channel Logs

Thursday, March 2, 2017

#haskell channel featuring pushp0p_, BANNED_IRL_BRO, pacak, lambdabot, lispy, pavonia, and 9 others.

MarcelineVQ 2017-03-02 17:45:57
alternatively: let g :: Int -> String; g i = show i
BANNED_IRL_BRO 2017-03-02 17:46:17
Alright..im down bitch
jle` 2017-03-02 17:46:49
sed -i 's/resolver:.*/resolver: lts-8.3/' ~/.stack/global-project/stack.yaml i suppose
jle` 2017-03-02 17:46:59
disclaimer i didn't test that
BANNED_IRL_BRO 2017-03-02 17:47:04
hello?!?!
jle` 2017-03-02 17:47:06
i don't know how regexes are supposed to be escaped in sed anymore
BANNED_IRL_BRO 2017-03-02 17:47:07
can;t you see im dope
BANNED_IRL_BRO 2017-03-02 17:47:09
baby im dope
BANNED_IRL_BRO 2017-03-02 17:47:13
can';t even type inm sod ope
lispy 2017-03-02 17:47:14
@ops
lambdabot 2017-03-02 17:47:14
Maybe you meant: pl oeis docs
BANNED_IRL_BRO 2017-03-02 17:47:17
blah balhb ablah
BANNED_IRL_BRO 2017-03-02 17:47:20
dont' bee so gay
BANNED_IRL_BRO 2017-03-02 17:47:23
im cool baby
jle` 2017-03-02 17:47:40
oh hey it worked
jle` 2017-03-02 17:48:01
between vim's regexes and grep's and sed's i always mix up what needs to be escaped
jle` 2017-03-02 17:48:09
especially cause you can toggle the regex mode in vim
Squarism 2017-03-02 17:48:16
MarcelineVQ, oh ok
pavonia 2017-03-02 17:52:28
Any hints on how to write a Parsec parser for this? http://lpaste.net/353165
pavonia 2017-03-02 17:53:22
The problem is that I don't know in advance which entry starts a section and which one is a simple one
maybefbi 2017-03-02 17:59:02
I want :: [[a]] -> [Int] -> [([a], [Int])] such that [Int] is "eaten" by the lengths of each [a] to make each ([a], [Int])
maybefbi 2017-03-02 17:59:23
i cant decide if it is a zipWith or something else
pavonia 2017-03-02 18:04:51
maybefbi: Do you have a sample for this? I don't know what you're looking for
Cale 2017-03-02 18:04:53
It's not entirely straightforward
S11001001 2017-03-02 18:05:41
maybefbi: I think you can replace Int with b, right?
S11001001 2017-03-02 18:05:48
maybefbi: in your types
maybefbi 2017-03-02 18:06:01
yes
S11001001 2017-03-02 18:06:36
maybefbi: it's not a zipWith, but it's a mapAccumL
Cale 2017-03-02 18:06:39
pavonia: I believe maybefbi wants f ["abc","de","fghi"] [1..] = [[('a',1),('b',2),('c',3)],[('d',4),('e',5)], ...]
pavonia 2017-03-02 18:07:08
Ah, thanks
maybefbi 2017-03-02 18:08:33
pavonia, example [[(),(),()], [()], [(), ()]] [2,7,1,8,2,8] = [([(),(),()], [2,7,1]). ([()], [8]), ([(), ()], [2, 8])]
Cale 2017-03-02 18:08:53
ohh, yeah, I misread that
Cale 2017-03-02 18:09:06
I thought you wanted it to pair them up one level deeper
maybefbi 2017-03-02 18:09:24
im thinking of some combination of zip and scanr
nshepperd 2017-03-02 18:09:33
it's what Cale said except `map unzip`d
maybefbi 2017-03-02 18:10:00
i could be wrong about zip + scanr
ertes 2017-03-02 18:10:10
pavonia: do you expect the grammar to get more complicated later?
maybefbi 2017-03-02 18:10:14
but the example is what im trying to achieve
ertes 2017-03-02 18:10:49
pavonia: if not, i'd honestly not use parsec at all… just split into lines and count leading spaces to determine nesting
ertes 2017-03-02 18:11:44
then you can use a one-line lookahead using e.g. a simple foldr
nshepperd 2017-03-02 18:11:46
f ass bs = zip ass (splitPlaces (map length ass) bs)
Cale 2017-03-02 18:11:51
> let next = do (x:xs) <- get; put xs; return x in evalState (mapM (mapM (\x -> fmap ((,) x) next)) ["abc","de","fghi"]) [1..]
lambdabot 2017-03-02 18:11:54
[[('a',1),('b',2),('c',3)],[('d',4),('e',5)],[('f',6),('g',7),('h',8),('i',9)]]
pavonia 2017-03-02 18:11:57
ertes: The grammar for each entry is already more complex, that's why I'd like to use a parser comibator for it. But yeah, doing a two-phase process is probably the easier solution
nshepperd 2017-03-02 18:12:20
(splitPlaces is from @hackage split)
ertes 2017-03-02 18:12:21
pavonia: you can still parse individual components with parsec
maybefbi 2017-03-02 18:12:28
:t splitPlaces
lambdabot 2017-03-02 18:12:28
Integral a => [a] -> [e] -> [[e]]
nshepperd 2017-03-02 18:12:37
oh hey, lambdabot has it
Cale 2017-03-02 18:12:45
> let next = do (x:xs) <- get; put xs; return x in map unzip $ evalState (mapM (mapM (\x -> fmap ((,) x) next)) ["abc","de","fghi"]) [1..]
nshepperd 2017-03-02 18:12:49
:t let f ass bs = zip ass (splitPlaces (map length ass) bs) in f
lambdabot 2017-03-02 18:12:50
[("abc",[1,2,3]),("de",[4,5]),("fghi",[6,7,8,9])]
lambdabot 2017-03-02 18:12:52
Foldable t => [t a] -> [e] -> [(t a, [e])]
ertes 2017-03-02 18:13:02
pavonia: i believe there is also a ready-made layout parser in trifecta… that might make it easier, too
nshepperd 2017-03-02 18:14:11
using `length` is a bit of laziness on my part, but it's easy to understand..
johnw_ 2017-03-02 18:14:38
nshepperd: was there a pun intended there?
nshepperd 2017-03-02 18:15:07
heh
Cale 2017-03-02 18:15:23
:t \us vs -> let next = do (x:xs) <- get; put xs; return x in evalState (mapM (mapM (\x -> fmap ((,) x) next)) us) vs
lambdabot 2017-03-02 18:15:26
(Traversable t1, Traversable t) => t (t1 a) -> [b] -> t (t1 (a, b))
pavonia 2017-03-02 18:16:02
ertes: This one? https://hackage.haskell.org/package/trifecta-0.52/docs/Text-Trifecta-Layout.html
nshepperd 2017-03-02 18:16:02
a bit of laziness, but not lazy enough
ertes 2017-03-02 18:16:26
pavonia: yeah, although i don't know how to use it
ertes 2017-03-02 18:16:50
pavonia: i suppose you transform Layout into Parser
ertes 2017-03-02 18:17:00
i.e. use the (Layout Parser) monad
maybefbi 2017-03-02 18:17:15
nshepperd, thanks
nshepperd 2017-03-02 18:17:30
@let choppy ass bs = zip ass (splitPlaces (map length ass) bs)
lambdabot 2017-03-02 18:17:34
Defined.
nshepperd 2017-03-02 18:17:48
> choppy ["abc","de","fghi"]) [1..]
lambdabot 2017-03-02 18:17:52
:1:27: error: parse error on input ')'
ertes 2017-03-02 18:18:01
pavonia: at least that's what the API suggests
nshepperd 2017-03-02 18:18:02
> choppy ["abc","de","fghi"] [1..]
lambdabot 2017-03-02 18:18:08
[("abc",[1,2,3]),("de",[4,5]),("fghi",[6,7,8,9])]
nshepperd 2017-03-02 18:18:14
excellent
maybefbi 2017-03-02 18:19:10
:)
nshepperd 2017-03-02 18:19:18
actually I guess this would be sufficiently lazy if I used genericLength with lazy peano nats there
pavonia 2017-03-02 18:19:46
ertes: Hhm, I guess I'll just do the structure parsing separately and use Parsec for the entries
ertes 2017-03-02 18:20:39
pavonia: reasonable… you can also easily use stream processing that way… parsec insists on having the whole input in memory
pushp0p_ 2017-03-02 18:26:07
hey i dont understand the function signature for: unfix :: Fix f -> f (Fix f)
pushp0p_ 2017-03-02 18:26:11
unfix (Fix f) = f
pushp0p_ 2017-03-02 18:26:18
it seems backwards to me
S11001001 2017-03-02 18:28:58
pushp0p_: what's the signature for Fix?
pushp0p_ 2017-03-02 18:29:37
fix :: f (Fix f) -> Fix f
pushp0p_ 2017-03-02 18:29:45
fix = Fix
S11001001 2017-03-02 18:29:52
pushp0p_: it's just the reverse of that
pushp0p_ 2017-03-02 18:30:29
yeah i understand they are reverse of each other
pushp0p_ 2017-03-02 18:30:50
its just weird that the signatures look like that to me
pushp0p_ 2017-03-02 18:31:08
is it point free style or something?
pacak 2017-03-02 18:31:10
Fix is a bit weird as it is.
pacak 2017-03-02 18:31:20
But useful
pushp0p_ 2017-03-02 18:32:29
yeah i understand what it does
pushp0p_ 2017-03-02 18:32:36
i just dont get why the signatures are like that i guess
pushp0p_ 2017-03-02 18:33:54
fix :: f (Fix f) -> Fix f
pushp0p_ 2017-03-02 18:34:01
^this looks like its 'tearing down a level of recursion'
pushp0p_ 2017-03-02 18:34:07
but its the opposite, right?
pushp0p_ 2017-03-02 18:34:55
nvm i guess i see it now looking at the type constructor for Fix
pushp0p_ 2017-03-02 18:35:27
https://jtobin.io/tour-of-some-recursive-types
ertes 2017-03-02 18:37:41
pushp0p_: let (x = Fix y) :: Fix F
ertes 2017-03-02 18:37:47
pushp0p_: what's the type of y?
pushp0p_ 2017-03-02 18:40:45
Fix (y (Fix y))
ertes 2017-03-02 18:41:05
pushp0p_: nope (and don't confuse the value level with the type level)
ertes 2017-03-02 18:41:10
Fix y :: Fix F
ertes 2017-03-02 18:41:12
y :: ?
pushp0p_ 2017-03-02 18:41:40
i honestly don't know haskell at all
pushp0p_ 2017-03-02 18:41:47
i'm just reading this article to try to understand recursive types
ertes 2017-03-02 18:42:01
pushp0p_: look at the definition of Fix
ertes 2017-03-02 18:42:13
newtype Fix f = Fix { unFix :: f (Fix f) }
ertes 2017-03-02 18:42:36
the Fix data constructor takes one argument of type (f (Fix f))
pushp0p_ 2017-03-02 18:43:16
yeah
ertes 2017-03-02 18:43:22
let (blah :: Blubb (Fix Blubb))
ertes 2017-03-02 18:43:29
then: Fix blah :: Fix Blubb
ertes 2017-03-02 18:43:33
does that make sense?
pushp0p_ 2017-03-02 18:44:24
yeah