From c.aman204 at gmail.com Mon Jan 6 06:48:18 2020
From: c.aman204 at gmail.com (Aman Choubey)
Date: Mon, 6 Jan 2020 12:18:18 +0530
Subject: [Haskell-beginners] Seeking Guidance/ Help for contibuting On
Haskell
Message-ID:
Hello
sir,
I am Aman Choubey, new to the developers world,a second year student from a
third tier college , I would like to start contributing to open source and
start working on Haskell Organization.
My skills Involve HTML,CSS ,JS5,Pytthon,C,C++ ,Mysql i currently learning
node.js,express.js.
can you suggest me the skill i should i start working on for working on The
Haskell Foundation,
and Some Good first issues.
Thank You
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From alexander at chenjia.nl Wed Jan 8 15:01:20 2020
From: alexander at chenjia.nl (Alexander Chen)
Date: Wed, 8 Jan 2020 16:01:20 +0100 (CET)
Subject: [Haskell-beginners] why doesn't this work?
Message-ID: <675050120.318296.1578495680883@ichabod.co-bxl>
hi,
for a List comprehension I want to only include the integers of a division. In my beginners mind this should work:
(round (x / y)) == (x / y)
however, i get a nontrivial error blurp.
what am i doing wrong?
best,
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From ollie at ocharles.org.uk Wed Jan 8 16:37:47 2020
From: ollie at ocharles.org.uk (Oliver Charles)
Date: Wed, 08 Jan 2020 16:37:47 +0000
Subject: [Haskell-beginners] why doesn't this work?
In-Reply-To: <675050120.318296.1578495680883@ichabod.co-bxl>
References: <675050120.318296.1578495680883@ichabod.co-bxl>
Message-ID:
On Wed, 8 Jan 2020, at 3:01 PM, Alexander Chen wrote:
> hi,
>
> for a List comprehension I want to only include the integers of a division. In my beginners mind this should work:
>
> (round (x / y)) == (x / y)
>
> however, i get a nontrivial error blurp.
Could you share what the "nontrivial error blurp" is? It will be easier for people to reply to you if they can see the problem without
having to reproduce it manually.
Ollie
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From utprimum at gmail.com Wed Jan 8 17:50:35 2020
From: utprimum at gmail.com (Ut Primum)
Date: Wed, 8 Jan 2020 18:50:35 +0100
Subject: [Haskell-beginners] why doesn't this work?
In-Reply-To: <675050120.318296.1578495680883@ichabod.co-bxl>
References: <675050120.318296.1578495680883@ichabod.co-bxl>
Message-ID:
Hi,
I think the problem is in the types.
If you look at the type of the function round, you can see its result is an
Integral:
>> :t round
round :: (Integral b, RealFrac a) => a -> b
The result of the division x/y, instead, is a Fractional, and you cannot
test equality between two things of different types.
To solve the problem you can do a type cast, by converting the Integral to
a Num, using fromInteger:
(fromInteger (round (x/y))) == (x/y)
This should work.
Cheers,
Ut
Il giorno mer 8 gen 2020 alle ore 16:01 Alexander Chen
ha scritto:
> hi,
>
> for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
>
> (round (x / y)) == (x / y)
>
> however, i get a nontrivial error blurp.
>
> what am i doing wrong?
>
> best,
>
> Alexander
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From toad3k at gmail.com Thu Jan 9 13:47:07 2020
From: toad3k at gmail.com (David McBride)
Date: Thu, 9 Jan 2020 08:47:07 -0500
Subject: [Haskell-beginners] why doesn't this work?
In-Reply-To: <675050120.318296.1578495680883@ichabod.co-bxl>
References: <675050120.318296.1578495680883@ichabod.co-bxl>
Message-ID:
Floating point comparisons are a bad idea.
A better way would be x `mod` y == 0.
On Wed, Jan 8, 2020 at 10:01 AM Alexander Chen wrote:
> hi,
>
> for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
>
> (round (x / y)) == (x / y)
>
> however, i get a nontrivial error blurp.
>
> what am i doing wrong?
>
> best,
>
> Alexander
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From aezarebski at gmail.com Thu Jan 9 23:51:29 2020
From: aezarebski at gmail.com (Alex Zarebski)
Date: Thu, 9 Jan 2020 23:51:29 +0000
Subject: [Haskell-beginners] Beginners Digest, Vol 139, Issue 2
In-Reply-To:
References:
Message-ID:
If the goal is to filter a list for numbers which are multiples of some
other number, perhaps the =mod= function would be a neater way to do this.
It is part of the Prelude with documentation here:
https://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#v:mod
On Thu, Jan 9, 2020 at 12:01 PM wrote:
> Send Beginners mailing list submissions to
> beginners at haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
> beginners-request at haskell.org
>
> You can reach the person managing the list at
> beginners-owner at haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
> 1. why doesn't this work? (Alexander Chen)
> 2. Re: why doesn't this work? (Oliver Charles)
> 3. Re: why doesn't this work? (Ut Primum)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 8 Jan 2020 16:01:20 +0100 (CET)
> From: Alexander Chen
> To: beginners at haskell.org
> Subject: [Haskell-beginners] why doesn't this work?
> Message-ID: <675050120.318296.1578495680883 at ichabod.co-bxl>
> Content-Type: text/plain; charset="utf-8"
>
> hi,
>
> for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
>
> (round (x / y)) == (x / y)
>
> however, i get a nontrivial error blurp.
>
> what am i doing wrong?
>
> best,
>
> Alexander
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20200108/90275f59/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Wed, 08 Jan 2020 16:37:47 +0000
> From: "Oliver Charles"
> To: beginners at haskell.org
> Subject: Re: [Haskell-beginners] why doesn't this work?
> Message-ID:
> Content-Type: text/plain; charset="utf-8"
>
> On Wed, 8 Jan 2020, at 3:01 PM, Alexander Chen wrote:
> > hi,
> >
> > for a List comprehension I want to only include the integers of a
> division. In my beginners mind this should work:
> >
> > (round (x / y)) == (x / y)
> >
> > however, i get a nontrivial error blurp.
>
> Could you share what the "nontrivial error blurp" is? It will be easier
> for people to reply to you if they can see the problem without
> having to reproduce it manually.
>
> Ollie
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20200108/57c13db7/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 3
> Date: Wed, 8 Jan 2020 18:50:35 +0100
> From: Ut Primum
> To: Alexander Chen , The Haskell-Beginners
> Mailing List - Discussion of primarily beginner-level topics
> related
> to Haskell
> Subject: Re: [Haskell-beginners] why doesn't this work?
> Message-ID:
> <
> CANjDmKJMRAjErGQeRE4cr0GmASQh2Dnh36PW4hvw_Ekdu3CNaQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi,
> I think the problem is in the types.
> If you look at the type of the function round, you can see its result is an
> Integral:
>
> >> :t round
> round :: (Integral b, RealFrac a) => a -> b
>
> The result of the division x/y, instead, is a Fractional, and you cannot
> test equality between two things of different types.
> To solve the problem you can do a type cast, by converting the Integral to
> a Num, using fromInteger:
>
> (fromInteger (round (x/y))) == (x/y)
>
> This should work.
>
> Cheers,
> Ut
>
>
>
>
> Il giorno mer 8 gen 2020 alle ore 16:01 Alexander Chen <
> alexander at chenjia.nl>
> ha scritto:
>
> > hi,
> >
> > for a List comprehension I want to only include the integers of a
> > division. In my beginners mind this should work:
> >
> > (round (x / y)) == (x / y)
> >
> > however, i get a nontrivial error blurp.
> >
> > what am i doing wrong?
> >
> > best,
> >
> > Alexander
> >
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20200108/4efa2af4/attachment-0001.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 139, Issue 2
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From alexander at chenjia.nl Wed Jan 15 14:41:00 2020
From: alexander at chenjia.nl (Alexander Chen)
Date: Wed, 15 Jan 2020 15:41:00 +0100 (CET)
Subject: [Haskell-beginners] Prime numbers -- specific list comprehension
explained
Message-ID: <673337005.3058.1579099260034@ichabod.co-bxl>
Hi,
This could gives you for any given integer the list of prime numbers. source is from a stack overflow snippet.
helper function:
isqrt :: Integral a => a -> a
isqrt = floor . sqrt . fromIntegral
main function:
primes 1 = []
primes n = 2:[i | i <- [3,5..n], and [mod i k /= 0 | k <- primes (isqrt i)]]
my main unclarity is how I should interpret i and k in de mod part. At every step of the recursion.
example: primes 10.
it should generate [2,3,5,7,9] if you ignore the second part.
however, when I look at the second part
then first I need to do this primes (isqrt 10), which give primes 3. which gives met [2,3].
first question) I haven't reached base case in this situations so can i or can i not meaningfully evaluate mod i k /= 0?
Independent of that I now go deeper to reach base case.
So I go to primes (isqrt 3) which gives me primes 1 which is []. Now I hit the base case and need to definitely evaluate mod i k /= 0.
second question) but in this case what is i and what is k?
If I have it completely wrong, then please be patience. I appreciate the input!
best,
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From utprimum at gmail.com Wed Jan 15 15:48:20 2020
From: utprimum at gmail.com (Ut Primum)
Date: Wed, 15 Jan 2020 16:48:20 +0100
Subject: [Haskell-beginners] Prime numbers -- specific list
comprehension explained
In-Reply-To: <673337005.3058.1579099260034@ichabod.co-bxl>
References: <673337005.3058.1579099260034@ichabod.co-bxl>
Message-ID:
Hi,
First I'll answer your second question:
but in this case what is i and what is k?
(So the question is about primes 3)
Think about the meaning of the expression primes 3, which is:
primes 3 = 2:[i | i <- [3,5..3], and [mod i k /= 0 | k <- primes (isqrt i)]]
= 2:*[i | i <- [3], and [mod i k /= 0 | k <- primes (isqrt
i)]] *
So, in the list *[i | i <- [3], and [mod i k /= 0 | k <- primes (isqrt
i)]]* i takes all values in the list *[3]* (i.e. it is only 3) and for
each of them the condition
*[mod i k /= 0 | k <- primes (isqrt i)] *
must be checked. When i=3, it is *[mod 3 k /= 0 | k <- primes 1] * = *
[mod 3 k /= 0 | k <- []]*, so the condition is empty (it means you must
check that mod 3 k is nonzero for every k in the empty list, so you don't
need to check anything!).
So this is clearly primes 3 = 2:*[3]* = [2,3].
To understand better, if you had:
[i | i <- [3,4,5,6], and [mod i k /= 0 | k <- []]]
(this never occurs in the program, but just to understand what i and k are)
i would be respectively 3,4,5 and 6 and for each i, k would be nothing. So
the list above is equal to [3,4,5,6].
Now maybe the meaning of this kind of expressions is mor clear, and you can
see that what you imagined the function did is not completely correct:
primes 10 = 2:[i | i <- [3,5,7,9], and [mod i k /= 0 | k <- primes (isqrt
i)]]
So, i is not 10 (so you don't always take k in primes 3), since it varies
among the values 3,5,7 and 9.
When i is 3, as I said before, k is in primes 1 = [], so there is no
further condition to check, so 3 is in the list.
When i is 5, k is in primes (isqrt 5) = primes 2 = [2], so you have to
check if mod 5 2 is nonzero, and it is, so 5 is in the list.
When i is 7, k is in primes (isqrt 7) = primes 2 = [2], so you have to
check if mod 7 2 is nonzero, and it is, so 7 is in the list.
When i is 9, k is in primes (isqrt 9) = primes 3 = [2,3], so you have to
check if mod 9 2 is nonzero and mod 9 3 is nonzero, but this is false, so 9
is NOT in the list.
As for your first question (which is now about something that happens for
i=9, not for i=10 which never happens, n=10, not i, so you never look at primes
(isqrt 10), but the answer would be the same, there is no difference)
I haven't reached base case in this situations so can i or can i not
meaningfully evaluate* mod i k /= 0*?
The answer is that of course you have to evaluate primes 3 before. So when
the expression is reduced, first primes 3 is calculated (and as you said it
gives [2,3]), and then mod i k /=0 can be evaluated because you know where
both i and k vary.
I hope it is clear,
cheers,
Ut
Il giorno mer 15 gen 2020 alle ore 15:49 Alexander Chen <
alexander at chenjia.nl> ha scritto:
> Hi,
>
> This could gives you for any given integer the list of prime numbers.
> source is from a stack overflow snippet.
>
> helper function:
> isqrt :: Integral a => a -> a
> isqrt = floor . sqrt . fromIntegral
>
> main function:
> primes 1 = []
> primes n = 2:[i | i <- [3,5..n], and [mod i k /= 0 | k <- primes (isqrt
> i)]]
>
>
>
> my main unclarity is how I should interpret i and k in de mod part. At
> every step of the recursion.
>
> example: *primes 10*.
>
> it should generate *[2,3,5,7,9]* if you ignore the second part.
>
> however, when I look at the second part
>
> then first I need to do this *primes (isqrt 10)*, which give primes 3.
> which gives met *[2,3]*.
> first question) I haven't reached base case in this situations so can i or
> can i not meaningfully evaluate* mod i k /= 0*?
> Independent of that I now go deeper to reach base case.
> So I go to *primes (isqrt 3)* which gives me primes 1 which is *[]*. Now
> I hit the base case and need to definitely evaluate *mod i k /= 0.*
> second question) but in this case what is i and what is k?
>
> If I have it completely wrong, then please be patience. I appreciate the
> input!
>
> best,
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From jake at vossen.dev Wed Jan 15 17:26:31 2020
From: jake at vossen.dev (Jake Vossen)
Date: Wed, 15 Jan 2020 17:26:31 +0000
Subject: [Haskell-beginners] Code review request?
Message-ID: <76a009d5-1586-5253-dd42-5c9bc1d6303c@vossen.dev>
Hey everyone,
Let me know if this is not the right place for this, but I am curious if
someone could take a look at my code and maybe share some feedback / how
a more experienced haskeller would approach this problem.
New to Haskell, pretty experienced with imperative languages. I have
solved the following problem in Haskell:
> Given a non-empty array, return true if there is a place to split the
> array so that the sum of the numbers on one side is equal to the sum
> of the numbers on the other side.
> canBalance([1, 1, 1, 2, 1]) -> true
> canBalance([2, 1, 1, 2, 1]) -> false
> canBalance([10, 10]) -> true
Here is my code (my solution uses `can_split_even` not `canBalance`)
```
can_split_even :: (Num a) => (Eq a) => [a] -> Bool
can_split_even xs = True `elem` is_even_at_each_spot
where
is_even_at_each_spot :: [Bool]
is_even_at_each_spot = map (is_split xs) [1 .. (length xs - 1)]
where
is_split :: (Num a) => (Eq a) => [a] -> Int -> Bool
is_split xs index = sum (take index xs) == sum (drop index xs)
```
Thanks so much!
--
Jake Vossen
Colorado School of Mines, Class of 2022
B.S. Computer Science
PGP: 08CD 67DA FE3A 0AE7 B946 6AC3 B812 7052 D9E3 817B
https://jake.vossen.dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL:
From utprimum at gmail.com Wed Jan 15 18:54:03 2020
From: utprimum at gmail.com (Ut Primum)
Date: Wed, 15 Jan 2020 19:54:03 +0100
Subject: [Haskell-beginners] Code review request?
In-Reply-To: <76a009d5-1586-5253-dd42-5c9bc1d6303c@vossen.dev>
References: <76a009d5-1586-5253-dd42-5c9bc1d6303c@vossen.dev>
Message-ID:
Hi,
this is how I would have solved the exercise:
canBalanceRec [] _ _ = False
canBalanceRec (x:xs) s1 s2 = s1+x==s2-x || canBalanceRec xs (s1+x) (s2-x)
canBalance xs = s==0 || canBalanceRec xs 0 s where s=sum xs
Note that there is one difference: in this case
canBalance [-2,-2,4] = True
because I think I can split the list into [ ] and the rest (since the sum
of the empty list is 0 and the same is the sum of the elements of the
lists). Anyway this is a matter of how we interpret the text of the
exercise (your function would return False instead). Note that removing the
"s==0 ||" makes no difference.
An advantage of my solution is that it is less expensive, since its
computational complexity is linear in the length of the list xs. Yours uses
sum and drop many times, and so is slower. Just to have an idea of the
difference (using ghci interpreter):
> canBalance [1..10000]
False
(*0.02* secs, 6,974,552 bytes)
> can_split_even [1..10000]
False
(*5.60* secs, 11,395,843,384 bytes)
Cheers,
Ut
Il giorno mer 15 gen 2020 alle ore 18:27 Jake Vossen ha
scritto:
> Hey everyone,
>
> Let me know if this is not the right place for this, but I am curious if
> someone could take a look at my code and maybe share some feedback / how
> a more experienced haskeller would approach this problem.
>
> New to Haskell, pretty experienced with imperative languages. I have
> solved the following problem in Haskell:
>
> > Given a non-empty array, return true if there is a place to split the
> > array so that the sum of the numbers on one side is equal to the sum
> > of the numbers on the other side.
>
> > canBalance([1, 1, 1, 2, 1]) -> true
> > canBalance([2, 1, 1, 2, 1]) -> false
> > canBalance([10, 10]) -> true
>
> Here is my code (my solution uses `can_split_even` not `canBalance`)
>
> ```
> can_split_even :: (Num a) => (Eq a) => [a] -> Bool
> can_split_even xs = True `elem` is_even_at_each_spot
> where
> is_even_at_each_spot :: [Bool]
> is_even_at_each_spot = map (is_split xs) [1 .. (length xs - 1)]
> where
> is_split :: (Num a) => (Eq a) => [a] -> Int -> Bool
> is_split xs index = sum (take index xs) == sum (drop index xs)
> ```
>
> Thanks so much!
>
> --
> Jake Vossen
> Colorado School of Mines, Class of 2022
> B.S. Computer Science
> PGP: 08CD 67DA FE3A 0AE7 B946 6AC3 B812 7052 D9E3 817B
> https://jake.vossen.dev
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From tanuki at gmail.com Wed Jan 15 20:02:04 2020
From: tanuki at gmail.com (Akhra Gannon)
Date: Wed, 15 Jan 2020 12:02:04 -0800
Subject: [Haskell-beginners] Code review request?
In-Reply-To:
References: <76a009d5-1586-5253-dd42-5c9bc1d6303c@vossen.dev>
Message-ID:
Also worth noting that Ut's version can be expressed as a fold:
canBalanceElem x acc@(y, z, p) = if p then acc else let y'=y+x; z'=z-x in
(y', z', y'==z')
canBalanceFold xs = (\(_, _, p) -> p) $ foldr canBalanceElem (0, sum xs,
False) xs
On Wed, Jan 15, 2020 at 10:54 AM Ut Primum wrote:
> Hi,
> this is how I would have solved the exercise:
>
> canBalanceRec [] _ _ = False
> canBalanceRec (x:xs) s1 s2 = s1+x==s2-x || canBalanceRec xs (s1+x) (s2-x)
> canBalance xs = s==0 || canBalanceRec xs 0 s where s=sum xs
>
> Note that there is one difference: in this case
> canBalance [-2,-2,4] = True
> because I think I can split the list into [ ] and the rest (since the sum
> of the empty list is 0 and the same is the sum of the elements of the
> lists). Anyway this is a matter of how we interpret the text of the
> exercise (your function would return False instead). Note that removing the
> "s==0 ||" makes no difference.
>
> An advantage of my solution is that it is less expensive, since its
> computational complexity is linear in the length of the list xs. Yours uses
> sum and drop many times, and so is slower. Just to have an idea of the
> difference (using ghci interpreter):
>
> > canBalance [1..10000]
> False
> (*0.02* secs, 6,974,552 bytes)
> > can_split_even [1..10000]
> False
> (*5.60* secs, 11,395,843,384 bytes)
>
> Cheers,
> Ut
>
> Il giorno mer 15 gen 2020 alle ore 18:27 Jake Vossen ha
> scritto:
>
>> Hey everyone,
>>
>> Let me know if this is not the right place for this, but I am curious if
>> someone could take a look at my code and maybe share some feedback / how
>> a more experienced haskeller would approach this problem.
>>
>> New to Haskell, pretty experienced with imperative languages. I have
>> solved the following problem in Haskell:
>>
>> > Given a non-empty array, return true if there is a place to split the
>> > array so that the sum of the numbers on one side is equal to the sum
>> > of the numbers on the other side.
>>
>> > canBalance([1, 1, 1, 2, 1]) -> true
>> > canBalance([2, 1, 1, 2, 1]) -> false
>> > canBalance([10, 10]) -> true
>>
>> Here is my code (my solution uses `can_split_even` not `canBalance`)
>>
>> ```
>> can_split_even :: (Num a) => (Eq a) => [a] -> Bool
>> can_split_even xs = True `elem` is_even_at_each_spot
>> where
>> is_even_at_each_spot :: [Bool]
>> is_even_at_each_spot = map (is_split xs) [1 .. (length xs - 1)]
>> where
>> is_split :: (Num a) => (Eq a) => [a] -> Int -> Bool
>> is_split xs index = sum (take index xs) == sum (drop index xs)
>> ```
>>
>> Thanks so much!
>>
>> --
>> Jake Vossen
>> Colorado School of Mines, Class of 2022
>> B.S. Computer Science
>> PGP: 08CD 67DA FE3A 0AE7 B946 6AC3 B812 7052 D9E3 817B
>> https://jake.vossen.dev
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From juliancamilo.osorio at gmail.com Wed Jan 15 21:05:06 2020
From: juliancamilo.osorio at gmail.com (Julian Camilo Osorio)
Date: Wed, 15 Jan 2020 16:05:06 -0500
Subject: [Haskell-beginners] Code review request?
In-Reply-To:
References: <76a009d5-1586-5253-dd42-5c9bc1d6303c@vossen.dev>
Message-ID:
For what it's worth, this is an equivalent one-liner:
canBalance xs = any ((== sum xs) . (*2)) (scanl (+) 0 xs)
On Wed, 15 Jan 2020 at 15:02, Akhra Gannon wrote:
>
> Also worth noting that Ut's version can be expressed as a fold:
>
> canBalanceElem x acc@(y, z, p) = if p then acc else let y'=y+x; z'=z-x in (y', z', y'==z')
> canBalanceFold xs = (\(_, _, p) -> p) $ foldr canBalanceElem (0, sum xs, False) xs
>
>
> On Wed, Jan 15, 2020 at 10:54 AM Ut Primum wrote:
>>
>> Hi,
>> this is how I would have solved the exercise:
>>
>> canBalanceRec [] _ _ = False
>> canBalanceRec (x:xs) s1 s2 = s1+x==s2-x || canBalanceRec xs (s1+x) (s2-x)
>> canBalance xs = s==0 || canBalanceRec xs 0 s where s=sum xs
>>
>> Note that there is one difference: in this case
>> canBalance [-2,-2,4] = True
>> because I think I can split the list into [ ] and the rest (since the sum of the empty list is 0 and the same is the sum of the elements of the lists). Anyway this is a matter of how we interpret the text of the exercise (your function would return False instead). Note that removing the "s==0 ||" makes no difference.
>>
>> An advantage of my solution is that it is less expensive, since its computational complexity is linear in the length of the list xs. Yours uses sum and drop many times, and so is slower. Just to have an idea of the difference (using ghci interpreter):
>>
>> > canBalance [1..10000]
>> False
>> (0.02 secs, 6,974,552 bytes)
>> > can_split_even [1..10000]
>> False
>> (5.60 secs, 11,395,843,384 bytes)
>>
>> Cheers,
>> Ut
>>
>> Il giorno mer 15 gen 2020 alle ore 18:27 Jake Vossen ha scritto:
>>>
>>> Hey everyone,
>>>
>>> Let me know if this is not the right place for this, but I am curious if
>>> someone could take a look at my code and maybe share some feedback / how
>>> a more experienced haskeller would approach this problem.
>>>
>>> New to Haskell, pretty experienced with imperative languages. I have
>>> solved the following problem in Haskell:
>>>
>>> > Given a non-empty array, return true if there is a place to split the
>>> > array so that the sum of the numbers on one side is equal to the sum
>>> > of the numbers on the other side.
>>>
>>> > canBalance([1, 1, 1, 2, 1]) -> true
>>> > canBalance([2, 1, 1, 2, 1]) -> false
>>> > canBalance([10, 10]) -> true
>>>
>>> Here is my code (my solution uses `can_split_even` not `canBalance`)
>>>
>>> ```
>>> can_split_even :: (Num a) => (Eq a) => [a] -> Bool
>>> can_split_even xs = True `elem` is_even_at_each_spot
>>> where
>>> is_even_at_each_spot :: [Bool]
>>> is_even_at_each_spot = map (is_split xs) [1 .. (length xs - 1)]
>>> where
>>> is_split :: (Num a) => (Eq a) => [a] -> Int -> Bool
>>> is_split xs index = sum (take index xs) == sum (drop index xs)
>>> ```
>>>
>>> Thanks so much!
>>>
>>> --
>>> Jake Vossen
>>> Colorado School of Mines, Class of 2022
>>> B.S. Computer Science
>>> PGP: 08CD 67DA FE3A 0AE7 B946 6AC3 B812 7052 D9E3 817B
>>> https://jake.vossen.dev
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
From Leonhard.Applis at protonmail.com Thu Jan 16 10:15:32 2020
From: Leonhard.Applis at protonmail.com (Leonhard Applis)
Date: Thu, 16 Jan 2020 10:15:32 +0000
Subject: [Haskell-beginners] Parallel Processing in Libraries?
Message-ID: <2MKFj_uwsGLJVa39UEnu8rSYWGYLs2thwMKEytWB6FyyH82uI6dR1qCai3NNOpLC3wJiJ_GHBMkAfyY6WYhRwDqsmleDInE7R7KSELQqPQc=@protonmail.com>
Hi,
I'm starting to dip into Parallel Processing with Haskell while reading "Parallel and Concurrent Programming in Haskell".
All the Examples in the Book construct a program which is doing all the work, so with all files in the same program which has a main method.
I'd like to have a library which utilized parallel programming (mostly for map-reduce tasks).
Is this possible?
My first approach of putting the par-code in my library and running the program threaded does not seem to use multiple cores.
Also I have not seen any parallel programming in "popular" libraries (such as QuickCheck) which makes me think that I'm on the wrong path.
To summarize my goal:
I want to build a computation-intensive library, which utilizes multiple cores when used from an executable.
Thank you
Leonhard
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: publickey - Leonhard.Applis at protonmail.com - 0x807FDDF3.asc
Type: application/pgp-keys
Size: 1843 bytes
Desc: not available
URL:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 477 bytes
Desc: OpenPGP digital signature
URL:
From tanuki at gmail.com Thu Jan 16 20:43:10 2020
From: tanuki at gmail.com (Akhra Gannon)
Date: Thu, 16 Jan 2020 12:43:10 -0800
Subject: [Haskell-beginners] Parallel Processing in Libraries?
In-Reply-To: <2MKFj_uwsGLJVa39UEnu8rSYWGYLs2thwMKEytWB6FyyH82uI6dR1qCai3NNOpLC3wJiJ_GHBMkAfyY6WYhRwDqsmleDInE7R7KSELQqPQc=@protonmail.com>
References: <2MKFj_uwsGLJVa39UEnu8rSYWGYLs2thwMKEytWB6FyyH82uI6dR1qCai3NNOpLC3wJiJ_GHBMkAfyY6WYhRwDqsmleDInE7R7KSELQqPQc=@protonmail.com>
Message-ID:
If you're looking for existing concurrency libraries, I would start here
and explore backwards through the dependencies if you need a lower-level
API:
https://hackage.haskell.org/package/lifted-async-0.10.0.4/docs/Control-Concurrent-Async-Lifted.html
On Thu, Jan 16, 2020, 2:16 AM Leonhard Applis <
Leonhard.Applis at protonmail.com> wrote:
> Hi,
>
> I'm starting to dip into Parallel Processing with Haskell while reading
> "Parallel and Concurrent Programming in Haskell".
> All the Examples in the Book construct a program which is doing all the
> work, so with all files in the same program which has a main method.
>
> I'd like to have a library which utilized parallel programming (mostly for
> map-reduce tasks).
>
>
>
> Is this possible?
>
> My first approach of putting the par-code in my library and running the
> program threaded does not seem to use multiple cores.
> Also I have not seen any parallel programming in "popular" libraries (such
> as QuickCheck) which makes me think that I'm on the wrong path.
>
> To summarize my goal:
> I want to build a computation-intensive library, which utilizes multiple
> cores when used from an executable.
>
> Thank you
> Leonhard
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From seb at sebleblanc.net Sun Jan 19 20:42:51 2020
From: seb at sebleblanc.net (=?UTF-8?Q?S=c3=a9bastien_Leblanc?=)
Date: Sun, 19 Jan 2020 15:42:51 -0500
Subject: [Haskell-beginners] Parallel Processing in Libraries?
In-Reply-To:
References:
Message-ID: <8b786165-cb63-de7f-43f0-33a0b083e8c4@sebleblanc.net>
> I'd like to have a library which utilized parallel programming (mostly for map-reduce tasks).
Since parallel computation is a complex topic, there are many solutions
that might not apply to a problem. I find that often, the simplest,
often overlooked method of implementing parallel computation is by
breaking down a problem into chunks that can easily be computed by a
single core.
Multi-threading is another topic entirely, and while it is often related
to parallelization, it is also often used only to allocate more cores
(improve performance) rather than implement an algorithm that is
otherwise serial, but then you get to have to deal with all the
difficulty of multi-threading like synchronization, shared memory
access, thread-safe code, having to deal with errors potentially
affecting the whole process vs. a single worker.
Thus, once you break down the problem into individual components, one
way to implement parallelization is by using a message queue task list
system. The principle is pretty simple, using a message broker such as
RabbitMQ or ZeroMQ, workers connect to this message queue and listen to
messages from a controller telling them to process some data using some
function. First come, first served. Once the worker is done, the reply
is sent back to the message queue or it is made available by any other
means (for example in a folder with shared access). The worker could
then notify other workers to further process this data.
The elegance of this system lies in how flexible the actual hardware
architecture that processes the load can be. For example, using some
cloud provider, you can automatically spawn more VMs to process a higher
load of data, and discard the VMs once they get idle long enough. On a
single machine, you can fire up one or as many processes as you have
computing cores (if your workload is almost 100% CPU-bound) and let the
OS take care of scheduling the tasks.
I am not aware of a complete task processing library for Haskell; for an
example of a mature project that provides such features, check out
Celery on Python. If you cannot find a substitute, I suppose you could
always use Celery and run your Haskell code from inside the Python
interpreter.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 2464 bytes
Desc: not available
URL:
From Leonhard.Applis at protonmail.com Mon Jan 20 13:23:40 2020
From: Leonhard.Applis at protonmail.com (Leonhard Applis)
Date: Mon, 20 Jan 2020 13:23:40 +0000
Subject: [Haskell-beginners] Parallel Processing in Libraries?
Message-ID:
Thank you Akhra,
Thank you Sebastian,
I appreciate your help and feedback.
However my Question was maybe not clear enough.
So in general my task is perfectly fit for Control.Parallel and
if I'd make a program including the Code I want I could just put control.parallel in the right places and run the program threaded.
Lets call this Application A.
However for separation I'd like to have my primary code, the one which should be run parallel in a separate library, call it Library A.
Library A should be utilizing Control.Parallel.
I then want to have Application B using Library A with multiple Cores.
The code of Library A has still all the control.parallel in place which worked perfectly fine when run running Application A threaded.
When I run Application B only one core seems to be utilized.
I also don't see any kind of parallel Code in popular frameworks such as QuickCheck2 (which seems very fit for parallel approaches)
which makes me wonder if what I want is "not possible" the way I want it.
I'd like to get Application B (and potential more Application C,D) to utilize library A properly.
I am at the moment not looking for mitigations or parallel-enabling frameworks/libraries.
thank you in advance and best regards
Leonhard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: publickey - Leonhard.Applis at protonmail.com - 0x807FDDF3.asc
Type: application/pgp-keys
Size: 1843 bytes
Desc: not available
URL:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 477 bytes
Desc: OpenPGP digital signature
URL:
From toad3k at gmail.com Mon Jan 20 15:58:40 2020
From: toad3k at gmail.com (David McBride)
Date: Mon, 20 Jan 2020 10:58:40 -0500
Subject: [Haskell-beginners] Parallel Processing in Libraries?
In-Reply-To:
References:
Message-ID:
It is not clear to me exactly what you are doing, but I believe in order to
use Control.Parallel, you must pass "-threaded" and then some rts options
at run time in order to declare options like the number of cores, etc. It
is possible that you are running it in two different ways, threaded while
developing the library and non threaded while developing your application.
I would say that if you can eliminate that from consideration you might get
more thorough answers from the haskell-cafe mailing list, as the topic of
parallelism is a bit above the beginners list.
On Mon, Jan 20, 2020 at 8:24 AM Leonhard Applis <
Leonhard.Applis at protonmail.com> wrote:
> Thank you Akhra,
> Thank you Sebastian,
>
>
> I appreciate your help and feedback.
>
> However my Question was maybe not clear enough.
>
>
> So in general my task is perfectly fit for Control.Parallel and
>
> if I'd make a program including the Code I want I could just put
> control.parallel in the right places and run the program threaded.
>
> Lets call this Application A.
>
> However for separation I'd like to have my primary code, the one which
> should be run parallel in a separate library, call it Library A.
>
> Library A should be utilizing Control.Parallel.
> I then want to have Application B using Library A with multiple Cores.
>
> The code of Library A has still all the control.parallel in place which
> worked perfectly fine when run running Application A threaded.
>
> When I run Application B only one core seems to be utilized.
>
> I also don't see any kind of parallel Code in popular frameworks such as
> QuickCheck2 (which seems very fit for parallel approaches)
>
> which makes me wonder if what I want is "not possible" the way I want it.
>
>
> I'd like to get Application B (and potential more Application C,D) to
> utilize library A properly.
>
>
> I am at the moment not looking for mitigations or parallel-enabling
> frameworks/libraries.
>
>
> thank you in advance and best regards
> Leonhard
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From alexander at chenjia.nl Thu Jan 30 13:29:30 2020
From: alexander at chenjia.nl (Alexander Chen)
Date: Thu, 30 Jan 2020 14:29:30 +0100 (CET)
Subject: [Haskell-beginners] using both my personal .hs and a library
simultaneously + seeing a function
Message-ID: <1705802852.567929.1580390970059@ichabod.co-bxl>
Hi,
1) I have my own functions in a .hs file which i can load in winGCHI and use the functions without a problem. But I also need 1 function from a hackage library, which I have downloaded in my haskell folder. I can 'toggle' between both my personal .hs and the library but I cannot use them both at the same time. The library is Primes(just for clarity). How can I merge these two so I can continue my training?
2) Is there a way to see a function if you call it in winGCHI. I don't mean the type structure which you do with :t but really the function itself for instance(see bold):
circular_times :: Int -> [Int]
circular_times n = take (length (show n)) (iterate circular n)
thanks in advance.
best,
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From utprimum at gmail.com Thu Jan 30 14:07:20 2020
From: utprimum at gmail.com (Ut Primum)
Date: Thu, 30 Jan 2020 15:07:20 +0100
Subject: [Haskell-beginners] using both my personal .hs and a library
simultaneously + seeing a function
In-Reply-To: <1705802852.567929.1580390970059@ichabod.co-bxl>
References: <1705802852.567929.1580390970059@ichabod.co-bxl>
Message-ID:
Hi,
1) I'm not sure this is what you are looking for, but you could import the
module Primes (write "import Primes" at the beginning) in your .hs script,
so when loading the script you would load also Primes.
Another way:
*:load yourFile.hs*
*:module +Primes*
2) you can try with
*:list circular_times*
(This should print the line where the word "circular_times" appears for the
first time, the line before and after it)
Best,
Ut
Il gio 30 gen 2020, 14:29 Alexander Chen ha scritto:
> Hi,
>
> 1) I have my own functions in a .hs file which i can load in winGCHI and
> use the functions without a problem. But I also need 1 function from a
> hackage library, which I have downloaded in my haskell folder. I can
> 'toggle' between both my personal .hs and the library but I cannot use them
> both at the same time. The library is Primes(just for clarity). How can I
> merge these two so I can continue my training?
>
> 2) Is there a way to see a function if you call it in winGCHI. I don't
> mean the type structure which you do with :t but really the function itself
> for instance(see bold):
>
> circular_times :: Int -> [Int]
> *circular_times n = take (length (show n)) (iterate circular n)*
>
>
> thanks in advance.
>
> best,
>
> Alexander
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From timmelzer at gmail.com Thu Jan 30 14:08:58 2020
From: timmelzer at gmail.com (Norbert Melzer)
Date: Thu, 30 Jan 2020 15:08:58 +0100
Subject: [Haskell-beginners] using both my personal .hs and a library
simultaneously + seeing a function
In-Reply-To: <1705802852.567929.1580390970059@ichabod.co-bxl>
References: <1705802852.567929.1580390970059@ichabod.co-bxl>
Message-ID:
On Thu, Jan 30, 2020 at 2:29 PM Alexander Chen wrote:
> Hi,
>
> 1) I have my own functions in a .hs file which i can load in winGCHI and
> use the functions without a problem. But I also need 1 function from a
> hackage library, which I have downloaded in my haskell folder. I can
> 'toggle' between both my personal .hs and the library but I cannot use them
> both at the same time. The library is Primes(just for clarity). How can I
> merge these two so I can continue my training?
>
Do you use a stack or cabal project or a plain file collection?
For a stack or cabal project you need to properly define it as a
dependency, for plain files I'm not quite sure how it works, but I'd
experiment with the `-i` argument to adjust the search path.
>
>
2) Is there a way to see a function if you call it in winGCHI. I don't mean
> the type structure which you do with :t but really the function itself for
> instance(see bold):
>
> circular_times :: Int -> [Int]
> *circular_times n = take (length (show n)) (iterate circular n)*
>
Not that I am aware off.
>
>
> thanks in advance.
>
> best,
>
> Alexander
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: