Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: haskell on OpenBSD 5.5 (MJ Williams)
2. Re: A better way to "integrate" (Giacomo Tesio)
3. Project euler question (martin)
4. Re: A better way to "integrate" (Christopher Allen)
----------------------------------------------------------------------
Message: 1
Date: Wed, 21 May 2014 19:46:34 +0100
From: MJ Williams <[email protected]>
To: Michael S <[email protected]>, The Haskell-Beginners Mailing
List - Discussion of primarily beginner-level topics related to
Haskell <[email protected]>
Subject: Re: [Haskell-beginners] haskell on OpenBSD 5.5
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"; format=flowed
Any reason for installing OpenBSD and not NetBSD or FreeBSD? I think
you can run any Linux package including ghc on both of those.
At 20:10 20/05/2014, you wrote:
>Good day all,
>
>I installed OpenBSD 5.5 in order to learn haskell.
>There are a few glitches however. I installed the haskell-platform
>meta-package and the issues I noticed are:
>- hs-vector wouldn't install
>- ghci wouldn't start, the message: unable to load package `integer-gmp'
>
>Has anyone experienced the same issue? Is this happening on OpenBSD 5.4?
>Is this OpenBSD specific?
>
>Thanks in advance.
>
>
>
>_______________________________________________
>Beginners mailing list
>[email protected]
>http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Wed, 21 May 2014 22:03:01 +0200
From: Giacomo Tesio <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] A better way to "integrate"
Message-ID:
<CAHL7psHuYoCzT7NKD+yHTrfuUNOk9E7ZxErknRzSX=gszbc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Actually I wonder why we don't have both Num and Group, Ring, Field, etc...
With GeneralizedNewtypeDeriving it would be awesome!
Giacomo
On Wed, May 21, 2014 at 7:01 PM, David Thomas <[email protected]>wrote:
> Yes, it "should" - in that it would be more expressive and allow types
> to catch more errors. The current situation trades that away for
> reduced complexity. Make whatever judgement call you want regarding
> whether that was appropriate.
>
> On Wed, May 21, 2014 at 9:57 AM, Dimitri DeFigueiredo
> <[email protected]> wrote:
> > Thanks, the realization that price, cost and volume are different
> quantities
> > is exactly what led me to play around with the Units library.
> >
> > I have a problem with Num. Shouldn't it be broken up into the
> fundamentals
> > of abstract algebra: Group, Ring, Field, etc? Just like is done for
> > Functors,
> > Applicative Functors, Monads, etc. It would avoid having the
> > typechecker allow me to multiply a Meter by Meter to get another Meter
> > (instead of the correct unit Meter^2).
> >
> > Cheers,
> >
> > Dimitri
> >
> >
> > Em 21/05/14 10:39, Brent Yorgey escreveu:
> >
> >> Others have given examples of implementing this using a fold. I'd
> >> like to point out something else: by representing all these prices and
> >> volumes etc. as a bare numeric type, you are simply asking for
> >> trouble! The reason is that it allows many nonsensical operations.
> >> For example, you could add a price and a volume. Adding a price and a
> >> volume makes no sense, but if they are the same type then the compiler
> >> cannot help you catch such a silly mistake.
> >>
> >> I would do something like this:
> >>
> >> {-# LANGUAGE GeneralizedNewtypeDeriving #-}
> >>
> >> newtype Price = Price Double
> >> -- you could also do newtype Price a = Price a if you want the
> >> -- flexibility to be able to use any numeric type, though it's
> >> probably not necessary.
> >>
> >> newtype Volume = Volume Double
> >> deriving Num
> >> newtype Cost = Cost Double
> >> deriving Num
> >>
> >> Notice I made a third type Cost, which is the result of multiplying a
> >> Price by a Volume. If I understand the domain correctly, multiplying
> >> a Price by a Volume does not give you another Price (for example,
> >> would it make sense to multiply a Price by a Volume, and then take the
> >> result and multiply it by another Volume?). A Price represents the
> >> value of a single share or unit of currency, whereas a Cost just
> >> represents some arbitrary amount of money.
> >>
> >> Now, what sorts of operations can one do on these types? Notice I put
> >> "deriving Num" after Volume and Cost, which means that two Volumes can
> >> be added or subtracted to give another Volume, and similarly for Cost
> >> (unfortunately, it means they can also be multiplied, which is
> >> probably not sensible, but that's more a failing of the Num class
> >> which is not granular enough). We also should implement
> >>
> >> (.*) :: Price -> Volume -> Cost
> >> Price p .* Volume v = Cost (p * v)
> >>
> >> And now you can implement essentially any of the suggested solutions,
> >> but with more descriptive types like
> >>
> >> aggregate :: [(Price, Volume)] -> [(Cost, Volume)]
> >>
> >> and using (.*) in the key place instead of (*). And now the type
> >> checker will make sure you don't do silly things like add a Price and
> >> a Volume, or multiply a Cost by a Price! Hooray!
> >>
> >> -Brent
> >>
> >> On Tue, May 20, 2014 at 08:12:59PM -0600, Dimitri DeFigueiredo wrote:
> >>>
> >>> Awesome haskellers,
> >>>
> >>> I am coding up a little function that aggregates "ask orders" in a
> >>> currency exchange.
> >>> Another way to look at it, is that the function takes as input a
> >>> histogram or fdf (in list format) and outputs the cumulative
> >>> distribution cdf (also in list format). So we are kind of
> >>> "integrating" the input list.
> >>>
> >>> When given a list of asks in order of increasing price, the function
> >>> returns a list of points in the graph of the total supply curve.
> >>>
> >>> Here's an example:
> >>>
> >>> asks: returned list:
> >>>
> >>> [ (Price 42, Volume 0.5), [ (Price 21, Volume 0.5),
> >>> (Price 50, Volume 1 ), (Price 21+50=71, Volume 1.5),
> >>> (Price 55, Volume 0.2)] (Price 21+50+11=82,Volume 1.7)]
> >>>
> >>> the returned list gives us the total supply curve (price = y-axis,
> >>> quantity/volume = x-axis, so the order is flipped)
> >>>
> >>> Summarizing
> >>>
> >>> * We're adding up the volumes. The last volume on the list is the
> >>> total volume available for sale.
> >>> * We calculate the total amount to be paid to buy the current volume
> >>> (for each item in the list).
> >>>
> >>> I have written up a simple function to do this:
> >>>
> >>> aggregate :: Num a => [(a,a)] -> [(a,a)]
> >>> aggregate xs = aggregate' 0 0 xs
> >>>
> >>> aggregate' :: Num a => a -> a -> [(a,a)] -> [(a,a)]
> >>> aggregate' _ _ [] = []
> >>> aggregate' accX accY ((x,y):ls) = let accX' = accX + x * y
> >>> accY' = accY + y
> >>>
> >>> in (accX',accY') : aggregate'
> >>> accX' accY' ls
> >>>
> >>>
> >>> main = print $ aggregate [(42,0.5),(50,1),(55,0.2)]
> >>>
> >>> However, this does not look very good to me and it feels like I'm
> >>> reinventing the wheel.
> >>>
> >>> Question: Is there a better Haskell way to do this? I'm really anal
> >>> about making it easy to read.
> >>>
> >>> Thanks!
> >>>
> >>> Dimitri
> >>> _______________________________________________
> >>> Beginners mailing list
> >>> [email protected]
> >>> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://www.haskell.org/mailman/listinfo/beginners
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140521/eeac90e0/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 21 May 2014 22:09:24 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Project euler question
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
Hello all,
I tried to solve Problem 24 (https://projecteuler.net/problem=24) and came up
with the following solution:
import Data.List.Ordered
import Data.Char
elems = [0,1,2,3,4,5,6,7,8,9] :: [Int]
x = do
a <- elems
b <- elems `without` [a]
c <- elems `without` [a,b]
d <- elems `without` [a,b,c]
e <- elems `without` [a,b,c,d]
f <- elems `without` [a,b,c,d,e]
g <- elems `without` [a,b,c,d,e,f]
h <- elems `without` [a,b,c,d,e,f,g]
i <- elems `without` [a,b,c,d,e,f,g,h]
j <- elems `without` [a,b,c,d,e,f,g,h,i]
return [a,b,c,d,e,f,g,h,i,j]
without a b = minus a ( sort b)
solution = filter isDigit $ show $ (x !! 1000001)
-- "2783915640"
PE tells me that this is wrong, and I peeked the correct answer, which is
2783915460 (the 4 and 6 are swapped). So I
tried to find out where the correct answer is in my list x and added
y = filter (\(x,y) -> x == "2783915460") $ zip (map (filter isDigit . show) x)
[1..]
-- [("2783915460",1000000)]
How can that be? "solution" tells me that the millionth element is "2783915640"
but "y" tells me that "2783915460" is at
the millionth position? I just cannot see it.
------------------------------
Message: 4
Date: Wed, 21 May 2014 15:12:35 -0500
From: Christopher Allen <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] A better way to "integrate"
Message-ID:
<CADnndOroiFRmsCRgTnyY0UxmY+oJysJL7i2RGkH=d8N7=mx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> Actually I wonder why we don't have both Num and Group, Ring, Field,
etc...
There are mathy preludes if that's what you're into.
On Wed, May 21, 2014 at 3:03 PM, Giacomo Tesio <[email protected]> wrote:
> Actually I wonder why we don't have both Num and Group, Ring, Field,
> etc...
>
> With GeneralizedNewtypeDeriving it would be awesome!
>
> Giacomo
>
>
> On Wed, May 21, 2014 at 7:01 PM, David Thomas <[email protected]>wrote:
>
>> Yes, it "should" - in that it would be more expressive and allow types
>> to catch more errors. The current situation trades that away for
>> reduced complexity. Make whatever judgement call you want regarding
>> whether that was appropriate.
>>
>> On Wed, May 21, 2014 at 9:57 AM, Dimitri DeFigueiredo
>> <[email protected]> wrote:
>> > Thanks, the realization that price, cost and volume are different
>> quantities
>> > is exactly what led me to play around with the Units library.
>> >
>> > I have a problem with Num. Shouldn't it be broken up into the
>> fundamentals
>> > of abstract algebra: Group, Ring, Field, etc? Just like is done for
>> > Functors,
>> > Applicative Functors, Monads, etc. It would avoid having the
>> > typechecker allow me to multiply a Meter by Meter to get another Meter
>> > (instead of the correct unit Meter^2).
>> >
>> > Cheers,
>> >
>> > Dimitri
>> >
>> >
>> > Em 21/05/14 10:39, Brent Yorgey escreveu:
>> >
>> >> Others have given examples of implementing this using a fold. I'd
>> >> like to point out something else: by representing all these prices and
>> >> volumes etc. as a bare numeric type, you are simply asking for
>> >> trouble! The reason is that it allows many nonsensical operations.
>> >> For example, you could add a price and a volume. Adding a price and a
>> >> volume makes no sense, but if they are the same type then the compiler
>> >> cannot help you catch such a silly mistake.
>> >>
>> >> I would do something like this:
>> >>
>> >> {-# LANGUAGE GeneralizedNewtypeDeriving #-}
>> >>
>> >> newtype Price = Price Double
>> >> -- you could also do newtype Price a = Price a if you want the
>> >> -- flexibility to be able to use any numeric type, though it's
>> >> probably not necessary.
>> >>
>> >> newtype Volume = Volume Double
>> >> deriving Num
>> >> newtype Cost = Cost Double
>> >> deriving Num
>> >>
>> >> Notice I made a third type Cost, which is the result of multiplying a
>> >> Price by a Volume. If I understand the domain correctly, multiplying
>> >> a Price by a Volume does not give you another Price (for example,
>> >> would it make sense to multiply a Price by a Volume, and then take the
>> >> result and multiply it by another Volume?). A Price represents the
>> >> value of a single share or unit of currency, whereas a Cost just
>> >> represents some arbitrary amount of money.
>> >>
>> >> Now, what sorts of operations can one do on these types? Notice I put
>> >> "deriving Num" after Volume and Cost, which means that two Volumes can
>> >> be added or subtracted to give another Volume, and similarly for Cost
>> >> (unfortunately, it means they can also be multiplied, which is
>> >> probably not sensible, but that's more a failing of the Num class
>> >> which is not granular enough). We also should implement
>> >>
>> >> (.*) :: Price -> Volume -> Cost
>> >> Price p .* Volume v = Cost (p * v)
>> >>
>> >> And now you can implement essentially any of the suggested solutions,
>> >> but with more descriptive types like
>> >>
>> >> aggregate :: [(Price, Volume)] -> [(Cost, Volume)]
>> >>
>> >> and using (.*) in the key place instead of (*). And now the type
>> >> checker will make sure you don't do silly things like add a Price and
>> >> a Volume, or multiply a Cost by a Price! Hooray!
>> >>
>> >> -Brent
>> >>
>> >> On Tue, May 20, 2014 at 08:12:59PM -0600, Dimitri DeFigueiredo wrote:
>> >>>
>> >>> Awesome haskellers,
>> >>>
>> >>> I am coding up a little function that aggregates "ask orders" in a
>> >>> currency exchange.
>> >>> Another way to look at it, is that the function takes as input a
>> >>> histogram or fdf (in list format) and outputs the cumulative
>> >>> distribution cdf (also in list format). So we are kind of
>> >>> "integrating" the input list.
>> >>>
>> >>> When given a list of asks in order of increasing price, the function
>> >>> returns a list of points in the graph of the total supply curve.
>> >>>
>> >>> Here's an example:
>> >>>
>> >>> asks: returned list:
>> >>>
>> >>> [ (Price 42, Volume 0.5), [ (Price 21, Volume 0.5),
>> >>> (Price 50, Volume 1 ), (Price 21+50=71, Volume 1.5),
>> >>> (Price 55, Volume 0.2)] (Price 21+50+11=82,Volume 1.7)]
>> >>>
>> >>> the returned list gives us the total supply curve (price = y-axis,
>> >>> quantity/volume = x-axis, so the order is flipped)
>> >>>
>> >>> Summarizing
>> >>>
>> >>> * We're adding up the volumes. The last volume on the list is the
>> >>> total volume available for sale.
>> >>> * We calculate the total amount to be paid to buy the current volume
>> >>> (for each item in the list).
>> >>>
>> >>> I have written up a simple function to do this:
>> >>>
>> >>> aggregate :: Num a => [(a,a)] -> [(a,a)]
>> >>> aggregate xs = aggregate' 0 0 xs
>> >>>
>> >>> aggregate' :: Num a => a -> a -> [(a,a)] -> [(a,a)]
>> >>> aggregate' _ _ [] = []
>> >>> aggregate' accX accY ((x,y):ls) = let accX' = accX + x * y
>> >>> accY' = accY + y
>> >>>
>> >>> in (accX',accY') : aggregate'
>> >>> accX' accY' ls
>> >>>
>> >>>
>> >>> main = print $ aggregate [(42,0.5),(50,1),(55,0.2)]
>> >>>
>> >>> However, this does not look very good to me and it feels like I'm
>> >>> reinventing the wheel.
>> >>>
>> >>> Question: Is there a better Haskell way to do this? I'm really anal
>> >>> about making it easy to read.
>> >>>
>> >>> Thanks!
>> >>>
>> >>> Dimitri
>> >>> _______________________________________________
>> >>> Beginners mailing list
>> >>> [email protected]
>> >>> http://www.haskell.org/mailman/listinfo/beginners
>> >>
>> >> _______________________________________________
>> >> Beginners mailing list
>> >> [email protected]
>> >> http://www.haskell.org/mailman/listinfo/beginners
>> >
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected]
>> > http://www.haskell.org/mailman/listinfo/beginners
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140521/a16aef4f/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 71, Issue 27
*****************************************