Search Haskell Channel Logs

Sunday, January 29, 2017

#haskell channel featuring lambdabot, pikajude, systadmin, Lokathor, orzo, ongy,

systadmin 2017-01-28 21:18:08
Is there any Haskell module/libraries similar to Python's `math` module?
Lokathor 2017-01-28 21:18:19
probably
Lokathor 2017-01-28 21:18:25
what does math do?
systadmin 2017-01-28 21:20:27
Lokathor: it adds more math operators such as factorial
Lokathor 2017-01-28 21:20:49
well some operations are in base, some operations you might have to look elsewhere for
Lokathor 2017-01-28 21:20:53
depending on what operation you want
systadmin 2017-01-28 21:21:12
I'm looking for one with factorial
pikajude 2017-01-28 21:21:39
@let factorial n = product [1..n]
lambdabot 2017-01-28 21:21:42
Defined.
pikajude 2017-01-28 21:21:45
> factorial 5
lambdabot 2017-01-28 21:21:49
120
systadmin 2017-01-28 21:22:13
How does that expression work?
Lokathor 2017-01-28 21:22:17
systadmin, there's no built in factorial that's commonly used, because factorial is pretty easy to define yourself in Haskell, as you can see
pikajude 2017-01-28 21:22:23
> [1..5]
lambdabot 2017-01-28 21:22:26
[1,2,3,4,5]
Lokathor 2017-01-28 21:22:42
:t product
pikajude 2017-01-28 21:22:44
`product` does what you'd expect and that's what the .. operator does
lambdabot 2017-01-28 21:22:45
(Foldable t, Num a) => t a -> a
systadmin 2017-01-28 21:22:46
And the `product` does?
pikajude 2017-01-28 21:22:56
> product [2,3,4]
lambdabot 2017-01-28 21:22:58
24
Lokathor 2017-01-28 21:23:09
product multiplies together all the values in the Foldable you pass it
systadmin 2017-01-28 21:23:10
The `product` expression or whatever you call it, multiplies all integers in a list?
systadmin 2017-01-28 21:23:15
Or Foldable
Lokathor 2017-01-28 21:23:18
yes
pikajude 2017-01-28 21:23:20
it multiplies all Nums in a Foldable
Lokathor 2017-01-28 21:23:29
List, Set, Vector, etc are all usable with product
pikajude 2017-01-28 21:23:30
integers in a list is a specific case
systadmin 2017-01-28 21:23:54
Sounds fun
pikajude 2017-01-28 21:24:02
also, ((,) a)
pikajude 2017-01-28 21:24:07
for some reason
systadmin 2017-01-28 21:24:23
How do foldables work?
pikajude 2017-01-28 21:25:03
see http://hackage.haskell.org/package/base-4.9.1.0/docs/Data-Foldable.html
ongy 2017-01-28 21:25:38
you want to look at foldl/foldr, the entire class can be a bit confusing
Lokathor 2017-01-28 21:26:41
a Foldable is kinda like... uhm, any structure that lets you pull out a part at a time and work it into a total at the end
Lokathor 2017-01-28 21:26:58
it's hard to avoid saying "any structure that you can fold", but that's a pretty useless definition
ongy 2017-01-28 21:31:41
I alwasy want to say that a Foldable is a structure that can be traversed, than I think about Traversable and get confused
kirillow 2017-01-28 21:35:21
how do i just repeat a function indefinitely?
orzo 2017-01-28 21:35:39
kirillow: iterate
orzo 2017-01-28 21:35:45
:t iterate
lambdabot 2017-01-28 21:35:47
(a -> a) -> a -> [a]
orzo 2017-01-28 21:36:18
:t forever
lambdabot 2017-01-28 21:36:20
Applicative f => f a -> f b
glguy 2017-01-28 21:36:22
:t fix
lambdabot 2017-01-28 21:36:27
(a -> a) -> a
kirillow 2017-01-28 21:36:37
Mh.. this is in the context of an IO Monad
kirillow 2017-01-28 21:36:40
forever!
orzo 2017-01-28 21:36:52
kirillow: i'd prefer fix to forever
kirillow 2017-01-28 21:36:57
why?
orzo 2017-01-28 21:37:11
i don't trust forever not to give memory leaks in strange situations
Lokathor 2017-01-28 21:37:27
forever has special let expression magic to avoid that, if you look at the source
orzo 2017-01-28 21:37:32
meaning i suspect forever tickles a compiler bug
Lokathor 2017-01-28 21:37:35
...but the let expression magic might not always work >_>
systadmin 2017-01-28 21:40:30
:t =>
lambdabot 2017-01-28 21:40:33
error: parse error on input '=>'
Lokathor 2017-01-28 21:42:22
systadmin, => is special type signature syntax that seperates the type class limitations on a type from the rest of the type signature
Lokathor 2017-01-28 21:42:35
:t fromIntegral
lambdabot 2017-01-28 21:42:35
(Num b, Integral a) => a -> b
Lokathor 2017-01-28 21:42:49
so here, Num b and Integral a are limits put on the type signature that follows the =>
orzo 2017-01-28 21:44:32
they're usually called constraints
Lokathor 2017-01-28 21:44:48
ah yes, that's the word I was thinking of
systadmin 2017-01-28 21:45:01
So Num b and Integral a aren't part of the type signature?