Search Haskell Channel Logs

Friday, February 24, 2017

#haskell channel featuring merijn, ahihi, ertes, liste, brynser, slaterr, and 5 others.

lyxia 2017-02-24 02:48:30
slaterr: (***)
slaterr 2017-02-24 02:48:45
:t (***)
lambdabot 2017-02-24 02:48:48
Arrow a => a b c -> a b' c' -> a (b, b') (c, c')
slaterr 2017-02-24 02:49:12
hmm doesn't seem to work
slaterr 2017-02-24 02:49:15
> map (id *** (2^)) [0..10]
lambdabot 2017-02-24 02:49:18
error:
lambdabot 2017-02-24 02:49:18
• Could not deduce (Enum (b, b'0))
lambdabot 2017-02-24 02:49:18
from the context: (Num (b, b'), Num c', Integral b', Enum (b, b'))
lyxia 2017-02-24 02:49:34
slaterr: okay I misunderstood. What is y1
lyxia 2017-02-24 02:50:22
> map (id &&& (2^)) [0 ..]
lambdabot 2017-02-24 02:50:25
[(0,1),(1,2),(2,4),(3,8),(4,16),(5,32),(6,64),(7,128),(8,256),(9,512),(10,10...
slaterr 2017-02-24 02:50:36
thanks, that was it
slaterr 2017-02-24 02:50:53
I never learned (or understood) arrows, so I couldn't hoogle the type
stevenxl 2017-02-24 02:51:01
Hi folks. Does the term polymorphic type imply ad-hoc or parametric polymorphism? For example, [a] is polymorphic, but (a, b) -> a is not? Or are both polymorphic?
liste 2017-02-24 02:51:32
stevenxl: parametric usually
liste 2017-02-24 02:51:36
stevenxl: both are polymorphic
liste 2017-02-24 02:51:49
there's type variables present
stevenxl 2017-02-24 02:52:03
liste: Sweet! Thank you .
liste 2017-02-24 02:52:43
stevenxl: you're welcome
slaterr 2017-02-24 02:52:44
when would one use ***?
liste 2017-02-24 02:52:52
:t (***)
lambdabot 2017-02-24 02:52:55
Arrow a => a b c -> a b' c' -> a (b, b') (c, c')
merijn 2017-02-24 02:53:11
lyxia: Isn't that better replaced with bimap nowadays?
lyxia 2017-02-24 02:53:24
is it?
merijn 2017-02-24 02:53:29
:t bimap
lambdabot 2017-02-24 02:53:31
Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d
merijn 2017-02-24 02:53:34
:t (***)
lambdabot 2017-02-24 02:53:36
Arrow a => a b c -> a b' c' -> a (b, b') (c, c')
lyxia 2017-02-24 02:54:30
right they're equivalent in this context. That seems like a better choice. merijn++
stevenxl 2017-02-24 02:54:35
huh - null is an expression.
stevenxl 2017-02-24 02:55:26
oh i see
stevenxl 2017-02-24 02:55:36
is the list empty
liste 2017-02-24 02:55:36
stevenxl: it's a function actually
liste 2017-02-24 02:55:36
> null []
lambdabot 2017-02-24 02:55:36
True
stevenxl 2017-02-24 02:55:36
liste: I'm not trying to be pedantic. Well actually I am because it really helps me to learn things when I know the terminology (hence my previous question). But isn't a function an expression?
liste 2017-02-24 02:55:38
stevenxl: it is, you're correct
liste 2017-02-24 02:55:51
stevenxl: an expression, more specifically a function
liste 2017-02-24 02:55:58
also a value
stevenxl 2017-02-24 02:56:02
Yea! :-)
stevenxl 2017-02-24 02:58:23
I don't know if it's because I've tried this a million times, but Yet Another Haskell Tutorial is the tutorial that is finally clicking.
stevenxl 2017-02-24 02:58:30
(So far, of course).
stevenxl 2017-02-24 02:58:55
Only on chapter 4 so still early.
ertes 2017-02-24 02:58:58
slaterr: zipWith
ertes 2017-02-24 02:59:09
together with (***)
ertes 2017-02-24 02:59:30
> zipWith (f *** g) [1,2,3] [10,20,30]
merijn 2017-02-24 02:59:32
stevenxl: If we're gonna be pedantic, saying a function is an expression is a confusion of meta levels :)
lambdabot 2017-02-24 02:59:33
error:
lambdabot 2017-02-24 02:59:33
• Couldn't match type '(c0, c'0)' with 'Integer -> c'
lambdabot 2017-02-24 02:59:33
Expected type: (b0, b'0) -> Integer -> c
lyxia 2017-02-24 02:59:51
almost
ertes 2017-02-24 02:59:54
> zipWith ((^2) *** (*100)) [1,2,3] [10,20,30]
lambdabot 2017-02-24 02:59:56
error:
lambdabot 2017-02-24 02:59:56
• Couldn't match type '(b0, b'0)' with 'Integer -> c'
lambdabot 2017-02-24 02:59:56
Expected type: (b0, b'0) -> Integer -> c
merijn 2017-02-24 02:59:58
stevenxl: expressions are a grammar concept (i.e. what does the language look like) whereas functions are more of semantics concept
ertes 2017-02-24 03:00:01
err…
ertes 2017-02-24 03:00:02
oh
ertes 2017-02-24 03:01:33
curry (***), then
ertes 2017-02-24 03:02:12
> map (f *** g) (zip [1,2,3] [10,20,30])
lambdabot 2017-02-24 03:02:12
error:
lambdabot 2017-02-24 03:02:12
• Ambiguous type variable 'c0' arising from a use of 'show_M133918705352...
lambdabot 2017-02-24 03:02:12
prevents the constraint '(Show c0)' from being solved.
stevenxl 2017-02-24 03:02:12
merijn: Luckily for me, I understand what semantics vs syntax so I get what you are saying there. I haven't had it explained to me as such.
ertes 2017-02-24 03:02:12
lambdabot: i hereby terminate our friendship
stevenxl 2017-02-24 03:02:12
Can you explain what you mean by saying that an expression is more of a syntax?
stevenxl 2017-02-24 03:02:13
related to syntax**
merijn 2017-02-24 03:03:12
stevenxl: Expressions are a syntax notion (i.e. what was written in the source file), when it comes to executing things, you generally deal with values (and functions are values)
stevenxl 2017-02-24 03:03:39
merijn: That makes sense. OK got it. Thank you.
hits1911 2017-02-24 03:08:21
can we pattern match arguments such as "f n (2*m) = ....", that is, "f 3 4" gets n to match 3 and m to 2?
merijn 2017-02-24 03:09:13
hits1911: No, but you might be interested in viewpatterns?
merijn 2017-02-24 03:09:41
> let f n ((`div` 2) -> m) = (n, m) in f 3 4
lambdabot 2017-02-24 03:09:44
(3,2)
ahihi 2017-02-24 03:10:32
or perhaps ((`divMod` 2) -> (m, 0)) instead
merijn 2017-02-24 03:11:25
Alternatively, you can use pattern guards to avoid needing an extension
merijn 2017-02-24 03:11:49
> let f n m' | m <- m' `div` 2 = (n, m) in f 3 4
lambdabot 2017-02-24 03:11:52
(3,2)
hits1911 2017-02-24 03:12:50
is viewpatterns a ghc extension?
merijn 2017-02-24 03:13:12
Yeah
merijn 2017-02-24 03:13:26
The second one using pattern guards is standard Haskell2010, though
hits1911 2017-02-24 03:13:52
I'll go with pattern guards. Thank you very much.
ahihi 2017-02-24 03:17:47
> let f n m' | m <- m' `div` 2 = (n, m) in f 3 5 -- note that this will match odd numbers as well, which might not be what you want
lambdabot 2017-02-24 03:17:49
(3,2)
merijn 2017-02-24 03:18:30
yeah, if you wanna avoid that you can mix ahihi's solution with pattern guards
brynser 2017-02-24 03:38:51
> showFFloat (Just 2) 1.0 ""
lambdabot 2017-02-24 03:38:55
"1.00"
brynser 2017-02-24 03:39:05
https://hackage.haskell.org/package/base-4.9.1.0/docs/Numeric.html#v:showFFloat
brynser 2017-02-24 03:39:16
"if digs is Just d, then at most d digits after the decimal point are shown."
brynser 2017-02-24 03:39:33
To me, that makes it sound like the result should be 1, not 1.00
kuribas 2017-02-24 03:43:50
Is there a strict tuple type?
kuribas 2017-02-24 03:44:05
preferably unboxed?