Search Haskell Channel Logs

Friday, March 3, 2017

#haskell channel featuring glguy, robertkennedy, mauke, lambdabot, lep-delete, argent0, and 10 others.

nbro 2017-03-03 03:45:38
@Tuplanolla : I'm required to use pattern matching where appropriately required and this function should actually return a Maybe Int...
lambdabot 2017-03-03 03:45:38
Unknown command, try @list
robertkennedy 2017-03-03 03:45:44
> fromEnum 'c'
lambdabot 2017-03-03 03:45:47
99
Tuplanolla 2017-03-03 03:45:59
All these options!
robertkennedy 2017-03-03 03:46:56
> fromEnum '😎'
lambdabot 2017-03-03 03:46:58
128526
mauke 2017-03-03 03:47:16
> let unhex c | any (`inRange` c) [('0', '9'), ('A', 'F'), ('a', 'f')] = Just (digitToInt c) | otherwise = Nothing in unhex 'c'
lambdabot 2017-03-03 03:47:19
Just 12
mauke 2017-03-03 03:47:27
> let unhex c | any (`inRange` c) [('0', '9'), ('A', 'F'), ('a', 'f')] = Just (digitToInt c) | otherwise = Nothing in unhex 'g'
lambdabot 2017-03-03 03:47:29
Nothing
mauke 2017-03-03 03:47:56
nbro: you can shorten it but not with pattern matching
Tuplanolla 2017-03-03 03:48:40
Compress the code with gzip and then extract it at compile time with TH.
liste 2017-03-03 03:48:56
nbro: you can do "unhex x = case x in { '0' -> ... }"
lyxia 2017-03-03 03:49:09
vaibhavsagar: you have 1M lines, is the size of "values" going to be around that order of magnitude as well? then for each element you produce a set of size 20k.
nbro 2017-03-03 03:51:26
liste: case .. in ?
liste 2017-03-03 03:51:57
> case 5 in { 5 -> "five"; _ -> "not five; }
lambdabot 2017-03-03 03:52:00
:1:8: error: parse error on input 'in'
liste 2017-03-03 03:52:06
oh wait
liste 2017-03-03 03:52:07
brainfart
liste 2017-03-03 03:52:32
> case 5 of { 5 -> "five"; _ -> "not five"; }
lambdabot 2017-03-03 03:52:35
"five"
liste 2017-03-03 03:54:00
> let unhex x = case x of { '0' -> Just 0; '1' -> Just 1; '2' -> Just 2; _ -> Nothing } in unhex '2'
lambdabot 2017-03-03 03:54:05
Just 2
nbro 2017-03-03 03:57:06
liste: ok, that could actually work and I would not be using if-then-else (which I shouldn't be using in this exercise)… but this would be as cumbersome as the pattern matching solution
mauke 2017-03-03 03:57:54
nbro: case/of *is* pattern matching
nbro 2017-03-03 03:58:05
mauke: what does the | (i.e. the pipe) actually means in Haskell, for example you used it here: "let unhex c | any (`inRange` c) [('0', '9'), ('A', 'F'), ('a', 'f')] = Just (digitToInt c) | otherwise = Nothing in unhex 'g'"...
raylocal 2017-03-03 03:58:15
hi i have a question . why does this work pure (++"foobar") <*> ("foo", "bar")
raylocal 2017-03-03 03:58:33
but not -> pure (+2) <*> (2,3)
Ferdirand 2017-03-03 03:58:52
> pure (+2) <*> (2,3)
lambdabot 2017-03-03 03:58:55
error:
lambdabot 2017-03-03 03:58:56
• Ambiguous type variable 't0' arising from a use of 'show_M727212133103...
lambdabot 2017-03-03 03:58:56
prevents the constraint '(Show t0)' from being solved.
mauke 2017-03-03 03:59:18
nbro: in that case it introduces a "guard", i.e. a boolean condition in addition to the pattern match
Ferdirand 2017-03-03 03:59:19
> pure (+2) <*> (2,3) :: (Int,Int)
lambdabot 2017-03-03 03:59:22
error:
lambdabot 2017-03-03 03:59:22
• No instance for (Monoid Int) arising from a use of '<*>'
lambdabot 2017-03-03 03:59:22
• In the expression: pure (+ 2) <*> (2, 3) :: (Int, Int)
Tuplanolla 2017-03-03 03:59:44
> pure (+ 2) <*> (2, 3)
lambdabot 2017-03-03 03:59:49
(2,5)
mauke 2017-03-03 04:00:13
> mempty :: Integer
lambdabot 2017-03-03 04:00:19
0
mauke 2017-03-03 04:00:23
that's cheating
Tuplanolla 2017-03-03 04:00:25
You need a `Monoid` instance for this to work.
Ferdirand 2017-03-03 04:00:53
:t (+ 2)
lambdabot 2017-03-03 04:00:56
Num a => a -> a
Ferdirand 2017-03-03 04:00:57
:t (+2)
lambdabot 2017-03-03 04:01:00
Num a => a -> a
Ferdirand 2017-03-03 04:01:10
huh
Tuplanolla 2017-03-03 04:01:11
Check the constraint of `Monoid ((,) a)`, raylocal.
Tuplanolla 2017-03-03 04:01:31
Actually `Monoid ((,) a b)`.
raylocal 2017-03-03 04:01:50
yeah i was thinking that in that case this should work pure (++"test") <*> (2, "test") but it doesn't
robertkennedy 2017-03-03 04:02:00
?src instance Monoid ((,) a b)
lambdabot 2017-03-03 04:02:01
Source not found. It can only be attributed to human error.
nbro 2017-03-03 04:02:12
mauke: I can use a boolean condition in the left side of the definition of a function?!!
mauke 2017-03-03 04:02:36
nbro: sure
nbro 2017-03-03 04:03:34
mauke: can I use only guards in the left side of the function def?
mauke 2017-03-03 04:03:39
there are language extensions for even crazier things, such as pattern guards and view patterns
nbro 2017-03-03 04:03:45
to introduce a condition?
mauke 2017-03-03 04:04:08
function definition syntax is just sugar for case/of
mauke 2017-03-03 04:04:24
and I think guards work in any context where a pattern is allowed
mauke 2017-03-03 04:05:58
> let foo | False = 42 in foo
lyxia 2017-03-03 04:06:01
> pure (++ "test") <*> (2, "test") :: (Product Integer, String)
lambdabot 2017-03-03 04:06:01
*Exception: :3:5-20: Non-exhaustive patterns in function foo
glguy 2017-03-03 04:06:05
not lambda s
lambdabot 2017-03-03 04:06:06
(Product {getProduct = 2},"testtest")
lyxia 2017-03-03 04:06:20
raylocal: totally works ^
mauke 2017-03-03 04:06:36
> (\foo | False -> foo) 42
lambdabot 2017-03-03 04:06:39
:1:7: error: parse error on input '|'
glguy 2017-03-03 04:06:44
or do notation <-
Tuplanolla 2017-03-03 04:07:31
Why though?
vaibhavsagar 2017-03-03 04:08:03
@lyxia I just found out that HashSet is implemented in terms of Data.HashMap.Lazy
lambdabot 2017-03-03 04:08:03
Unknown command, try @list
vaibhavsagar 2017-03-03 04:08:10
maybe that is why?
glguy 2017-03-03 04:08:43
the @ is for bot commands
argent0 2017-03-03 04:09:37
Hi, I itend to use sqlite in haskell, is HDBC the prefered way?
nbro 2017-03-03 04:09:43
can we import modules or functions from modules only if the current file is defined as a module?
vaibhavsagar 2017-03-03 04:09:58
thanks glguy :)
mauke 2017-03-03 04:10:11
nbro: all files are modules
mauke 2017-03-03 04:10:41
if you don't have an explicit module declaration, it's 'module Main where'
argent0 2017-03-03 04:10:41
s/itend/want
nbro 2017-03-03 04:10:46
well, I've read that modules must be explicitly defined with a name that starts with a capital letter…
nbro 2017-03-03 04:11:07
mauke: ok, so I'm currently on the Main module
lyxia 2017-03-03 04:11:27
vaibhavsagar: that doesn't matter though. The laziness of HashMap only affects values, i.e., (), not keys.
mauke 2017-03-03 04:11:55
https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005.1
raylocal 2017-03-03 04:12:11
thanks Tuplanolla and lyxia . I understand that the monoid instance should be there for both the members of the tuple and not only the 2nd one as i has thought /imagined
lyxia 2017-03-03 04:12:14
vaibhavsagar: but isn't your program representing 20 billion elements?
liste 2017-03-03 04:12:25
argent0: check out https://hackage.haskell.org/package/sqlite-simple
raylocal 2017-03-03 04:12:28
i understand NOW i mean :)
lyxia 2017-03-03 04:12:47
vaibhavsagar: how did you expect it to fit
vaibhavsagar 2017-03-03 04:13:12
lyxia: are you saying that that is where the memory usage is coming from?
Tuplanolla 2017-03-03 04:13:21
For `Monoid` you need both, but `Applicative` only requires the first, raylocal.
vaibhavsagar 2017-03-03 04:13:24
not the intersection that I'm doing?
lyxia 2017-03-03 04:13:59
well the intersections surely don't help
vaibhavsagar 2017-03-03 04:16:02
fair call, I changed it so that I'm computing intersections when I first build the hashmap
argent0 2017-03-03 04:18:36
liste: thanks for the info
nbro 2017-03-03 04:26:21
mauke: I was looking at your solution of unhex, and there's one part that I actually didn't fully understand
nbro 2017-03-03 04:26:27
and which is: any (`inRange` c) [('0', '9'), ('A', 'F'), ('a', 'f')]
nbro 2017-03-03 04:26:33
:t any
lambdabot 2017-03-03 04:26:35
Foldable t => (a -> Bool) -> t a -> Bool
nbro 2017-03-03 04:26:50
any :: (a -> Bool) -> [a] -> Bool
nbro 2017-03-03 04:27:12
any requires a predicate
nbro 2017-03-03 04:27:33
in your example, apparently (`inRange` c) is the predicate
nbro 2017-03-03 04:27:40
:t inRange
lambdabot 2017-03-03 04:27:42
Ix a => (a, a) -> a -> Bool
benjwadams 2017-03-03 04:27:45
Where can I learn more about Haskell's build system? I've only dabbled with haskell, but I'm getting irritated with python's model breaking everything.
benjwadams 2017-03-03 04:27:57
heard mixed things about cabal
sm 2017-03-03 04:29:58
http://haskell-lang.org/get-started
vaibhavsagar 2017-03-03 04:30:22
benjwadams: https://docs.haskellstack.org/en/stable/README/
nbro 2017-03-03 04:31:05
:info inRange
mauke 2017-03-03 04:31:31
@hoogle inRange
lambdabot 2017-03-03 04:31:34
Data.Ix inRange :: Ix a => (a, a) -> a -> Bool
lambdabot 2017-03-03 04:31:34
Data.Ix.Enum inRange :: Enum a => (a, a) -> a -> Bool
lambdabot 2017-03-03 04:31:34
Data.Ord.HT inRange :: Ord a => (a, a) -> a -> Bool
nbro 2017-03-03 04:34:25
mauke: in the first signature of inRange function we have: Data.Ix inRange :: Ix a => (a, a) -> a -> Bool, we have that it receives two arguments, a tuple (a, a) and a
nbro 2017-03-03 04:35:00
but in your usage: any (`inRange` c) [('0', '9'), ('A', 'F'), ('a', 'f')], you don't seem to use the two arguments correctly
nbro 2017-03-03 04:35:10
maybe I'm just misinterpreting the signature
mauke 2017-03-03 04:35:59
nbro: do you know what ` ` does?
mauke 2017-03-03 04:36:30
also, you retyped the 'f' part. weird
nbro 2017-03-03 04:36:38
mauke: from my understanding it's used to make the function be infix
mauke 2017-03-03 04:36:52
correct
mauke 2017-03-03 04:37:11
do you know about operator sections?
mauke 2017-03-03 04:37:26
> (/ 2) 3
lambdabot 2017-03-03 04:37:30
1.5
nbro 2017-03-03 04:37:53
mm…I think I briefly saw something like that before
mauke 2017-03-03 04:38:08
> map (/ 2) [1 .. 10]
lambdabot 2017-03-03 04:38:11
[0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0]
nbro 2017-03-03 04:38:14
you essentially can precede the operator
nbro 2017-03-03 04:38:26
with the second part
mauke 2017-03-03 04:38:44
:t (`inRange` ?c)
lambdabot 2017-03-03 04:38:46
(?c::a, Ix a) => (a, a) -> Bool
mauke 2017-03-03 04:38:56
:t (`inRange` (?c :: Char))
lambdabot 2017-03-03 04:38:59
(?c::Char) => (Char, Char) -> Bool
lep-delete 2017-03-03 04:41:18
:t (`inRange` _)
lambdabot 2017-03-03 04:41:21
error:
lambdabot 2017-03-03 04:41:21
• Found hole: _ :: a
lambdabot 2017-03-03 04:41:21
Where: 'a' is a rigid type variable bound by
lep-delete 2017-03-03 04:41:26
:D
mauke 2017-03-03 04:42:09
@undo (`inRange` c)
lambdabot 2017-03-03 04:42:09
(`inRange` c)
mauke 2017-03-03 04:42:16
@unpl (`inRange` c)
lambdabot 2017-03-03 04:42:16
(\ a0 -> inRange a0 c)
tabaqui1 2017-03-03 04:42:59
I have one config file for my application
tabaqui1 2017-03-03 04:43:37
in Python I would parse it and put in one global singleton
tabaqui1 2017-03-03 04:44:04
because I don't want to pass fields up to down, from main to actual function
tabaqui1 2017-03-03 04:44:13
which pattern do you use in haskell?
tabaqui1 2017-03-03 04:44:20
*what pattern
tabaqui1 2017-03-03 04:46:51
ah, haskell wiki recommends to wrap the whole code into configuration monad