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:  How do I do inheritance in haskell? (Daniel Trstenjak)
   2. Re:  How do I do inheritance in haskell? (Daniel Trstenjak)
   3. Re:  How do I do inheritance in haskell? (Benjamin Edwards)
   4. Re:  How do I do inheritance in haskell? (David Thomas)
   5.  Problem with installing SDL (Julian Drube)
   6. Re:  Problem with installing SDL (Patrick Wheeler)
   7. Re:  How do I do inheritance in haskell? (Karl Voelker)


----------------------------------------------------------------------

Message: 1
Date: Thu, 8 May 2014 16:21:48 +0200
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How do I do inheritance in haskell?
Message-ID: <20140508142148.GA25718@machine>
Content-Type: text/plain; charset=us-ascii


Hi Dimitri,

> It is not clear to me which one of these should be used and, most importantly,
> which criteria should be used to choose between them.

One criteria should be what you want to achieve, how you want
to operate with your data.


> 1)
> newtype Volume = Volume Double deriving (Show)
> newtype Price  = Price  Double deriving (Show)
> 
> data Order = Bid {price::Price, volume::Volume}
>            | Ask {price::Price, volume::Volume}
>            deriving (Show)
> 
> data OrderBook = OrderBook{ bids::[Order] , asks::[Order] } deriving (Show)

This represenation of an Order gives you the ability to put Bids and
Asks e.g. into the same list, but if you always want to keep them
separate, then there's no point to have an ADT in the first place.


> 2)
> newtype Volume = Volume Double deriving (Show)
> newtype Price  = Price  Double deriving (Show)
> 
> data Order = Order {price::Price, volume::Volume} deriving (Show)
> 
> newtype Bid = Bid Order deriving Show
> newtype Ask = Ask Order deriving Show
> 
> data OrderBook = OrderBook{ bids::[Bid] , asks::[Ask] } deriving (Show)

If you want to keep Bids and Asks always separate, then this
represenation seems to be more fitting.


> 3)
> newtype Volume = Volume Double deriving (Show)
> newtype Price  = Price  Double deriving (Show)
> 
> class Order a where
>     makeOrder :: String -> String -> a
> 
> data Ask = Ask {aprice::Price, avolume::Volume} deriving (Show)
> instance Order Ask where
>     makeOrder = makeAsk
> 
> data Bid = Bid {bprice::Price, bvolume::Volume} deriving (Show)
> instance Order Bid where
>     makeOrder = makeBid
> 
> data OrderBook = OrderBook{ bids::[Bid] , asks::[Ask] } deriving (Show)

I might prefer the Asks and Bids data types of 2), because factoring out
the common parts might have future benefits, by being able to reuse
functionality on the common parts.

The type class here fulfills something completely different to the
previous two examples and is about the creation of your Asks and Bids.

I don't think that you really need this type class, but you could just
use makeAsk and makeBid without losing anything, because as long as your
types in OrderBook are fixed you gain nothing.


Greetings,
Daniel


------------------------------

Message: 2
Date: Thu, 8 May 2014 16:24:50 +0200
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How do I do inheritance in haskell?
Message-ID: <20140508142450.GB25718@machine>
Content-Type: text/plain; charset=us-ascii


Hi Dan,

On Thu, May 08, 2014 at 11:58:28AM +0300, Dan Serban wrote:
> newtype AskVolume = AskVolume Double deriving (Show)
> newtype AskPrice  = AskPrice  Double deriving (Show)
> 
> newtype BidVolume = BidVolume Double deriving (Show)
> newtype BidPrice  = BidPrice  Double deriving (Show)

I think that's a bit over the top, because why shouldn't prices 
and volumes be interchangeable between Asks and Bids?


Greetings,
Daniel


------------------------------

Message: 3
Date: Thu, 08 May 2014 14:28:21 +0000
From: Benjamin Edwards <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How do I do inheritance in haskell?
Message-ID:
        <can6k4njm+cfumjy-lydvyw3t-_wxuppon9mm6m9bzszrjwj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

>
> I think that's a bit over the top, because why shouldn't prices
> and volumes be interchangeable between Asks and Bids?


It's a good question. I guess as long as a price / volume is always wrapped
in a type that's tagged bid / ask then everything is great. You just want
to avoid being the next knight capital and ending up trading the wrong side
of the spread.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140508/685a558a/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 8 May 2014 08:49:51 -0700
From: David Thomas <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How do I do inheritance in haskell?
Message-ID:
        <cajudvcjdq1gci+ehbtnnpt2h4qjqade0yf05aoshktnz4_j...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Because confusing them is disastrous, so there is motivation to go to
extra lengths to keep them separate.  I don't have particular thoughts
on whether that motivation is sufficient in this case.

On Thu, May 8, 2014 at 7:24 AM, Daniel Trstenjak
<[email protected]> wrote:
>
> Hi Dan,
>
> On Thu, May 08, 2014 at 11:58:28AM +0300, Dan Serban wrote:
>> newtype AskVolume = AskVolume Double deriving (Show)
>> newtype AskPrice  = AskPrice  Double deriving (Show)
>>
>> newtype BidVolume = BidVolume Double deriving (Show)
>> newtype BidPrice  = BidPrice  Double deriving (Show)
>
> I think that's a bit over the top, because why shouldn't prices
> and volumes be interchangeable between Asks and Bids?
>
>
> Greetings,
> Daniel
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


------------------------------

Message: 5
Date: Thu, 08 May 2014 22:25:37 +0200
From: Julian Drube <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Problem with installing SDL
Message-ID: <7141757.TlrQdfbG5o@julianspc>
Content-Type: text/plain; charset="utf-8"

Hi,

i'm trying to install the SDL package with:

cabal install sdl

but the following error is showing up:

Graphics/UI/SDL/Events.hsc:56:23:
    Module ?Data.Typeable? does not export ?Typeable(typeOf)?
cabal: Error: some packages failed to install:
SDL-0.6.5 failed during the building phase. The exception was:
ExitFailure 1


GHC version is 7.8.2


Thanks in advance for any ideas
Julian


------------------------------

Message: 6
Date: Thu, 8 May 2014 17:43:41 -0500
From: Patrick Wheeler <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem with installing SDL
Message-ID:
        <CAAo_BYYq6xZpcjcYZOvfF0sLc0vNdW8G=k-kbme_p9jcmkp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The error is saying that it can not find `typeOf` in the `Typeable` class.
 This is because that function is not longer part of the `Typeable` in
ghc7.8 and moving forward.  Error like this are still be sorted out for ghc
7.8.  You are on a bleeding edge version of ghc so packaging problems like
this are expected.  Package stability is usually marked by when the Haskell
Platform updates to the new ghc version.

So if you want additional stability HP is where it is at. If you want to
live and the bleeding edge then you can download sdl with cabal unpack and
see if you can not fix the problem for yourself.

Here is a link to the `Typeable` module in base:
http://hackage.haskell.org/package/base-4.7.0.0/docs/Data-Typeable.htmlOf

There is replacement function for backward compatibility.
http://hackage.haskell.org/package/base-4.7.0.0/docs/Data-Typeable.html#v:typeOf

If you fixed the import statement for all of the sdl modules, you might fix
the incompatibility with the new Typeable.  There will probably be a few
other issues that need solving after this one. I have updated several
packages on a case by case basis when I need them to new ghc version and
has been a lesson in understanding ghc errors and fixing them. If you have
the time I recommend giving it a shot.

Patrick


On Thu, May 8, 2014 at 3:25 PM, Julian Drube <[email protected]> wrote:

> Hi,
>
> i'm trying to install the SDL package with:
>
> cabal install sdl
>
> but the following error is showing up:
>
> Graphics/UI/SDL/Events.hsc:56:23:
>     Module ?Data.Typeable? does not export ?Typeable(typeOf)?
> cabal: Error: some packages failed to install:
> SDL-0.6.5 failed during the building phase. The exception was:
> ExitFailure 1
>
>
> GHC version is 7.8.2
>
>
> Thanks in advance for any ideas
> Julian
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Patrick Wheeler
[email protected]
[email protected]
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140508/d060a948/attachment-0001.html>

------------------------------

Message: 7
Date: Thu, 08 May 2014 15:50:12 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How do I do inheritance in haskell?
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On Thu, May 8, 2014, at 01:26 AM, Dimitri DeFigueiredo wrote:

Now, I have to convert this (if possible) into an OrderBook type. An
orderbook is basically two lists. One list of the orders placed by
people who want to buy, the "bids", and the other with the orders of
people who want to sell, the "asks". Each order specifies what price
should be paid and how many bitcoins to buy/sell (the volume).



There are more representations you could choose.



One example, if you want bids and asks to have the same type:



data OrderType = Bid | Ask

data Order = Order OrderType Price Volume



And if you don't want them to have the same type:



data BidType -- requires -XEmptyDataDecls

data AskType

data Order a = Order Price Volume

type Bid = Order BidType

type Ask = Order AskType



-Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140508/75fa9313/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 71, Issue 11
*****************************************

Reply via email to