[Haskell-cafe] typeclass woes...how to constain a typeclass to be "closed" under an operation....

Nicholls, Mark nicholls.mark at vimn.com
Thu Jan 8 08:19:29 UTC 2015


Reading around this more i think the extreme case (of what im interested in) is type arithemetic, ie the set of type "inside" the container is not necessarily finite in general, but yes, i see how you construct works.

So in think for my specific purposes the associated type route is the first place for me to investigate

Excuse the spelling, sent from a phone with itty bitty keys, it like trying to sow a button on a shirt with a sausage.


On 7 Jan 2015, at 20:58, Akash Ganesan <akaberto at gmail.com<mailto:akaberto at gmail.com>> wrote:

If I understand the issue at hand, you want the container, which is
basically  a collection of types to be closed under our
operation.  Since we are dealing with set of different typed objects,
which is to be closed under a given operation, why not create a new type
that captures the essence of the set (ie., a new data type)? Something
like the following.

data S = SInt Int
       | SChar Char
       | STuple (Char, Char) deriving (Show, Eq)

class MyFoo a where
    op :: a -> a

And the instance goes something like this.

instance MyFoo S where
    op (SInt x)        = SInt $ toEnum x
    op (SChar x)    = STuple (x,x)
    op (STuple (x,y))    = SInt $ fromEnum x



On Tuesday, 6 January 2015 23:13:59 UTC+5:30, Nicholls, Mark wrote:
This is reposted from the beginnners….I’ve not done Haskell for a while and was struggling to get anything to work, I’ve hopefully refound my feet.

Its quite common in maths to have operations in a theory that are (set) closed, i just want to translate that notion to a typeclass

I have a suggestion that does work

class Foo m where
op :: m a -> m (S a)

That is closed, but now were working on types of kind • -> •

(S can be a type family or a data type…lets say it’s a type family….probably an associated type (if I know what that means))

Is this the idiom/pattern i should follow? Or can the closure contraint be expressed directly in a typeclass any other way?


From: Haskell-Cafe [mailto:haskell-ca... at haskell.org<javascript:>] On Behalf Of Brandon Allbery
Sent: 06 January 2015 1:59 PM
To: Rob Leslie
Cc: Haskell Cafe
Subject: Re: [Haskell-cafe] Haskeline and asynchronous messages

On Tue, Jan 6, 2015 at 3:27 AM, Rob Leslie <r... at mars.org<javascript:>> wrote:
Does anyone have a suggestion on using Haskeline in an environment where another thread may be writing messages to the terminal -- is it possible to somehow print incoming messages above the input line without disturbing the input line?

Terminals don't really work that way; you need to be looking at something like curses or vty.

--
brandon s allbery kf8nh                               sine nomine associates
allb... at gmail.com<javascript:>                                  ball... at sinenomine.net<javascript:>
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net


CONFIDENTIALITY NOTICE

This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.

While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.

Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
CONFIDENTIALITY NOTICE

This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.

While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.

Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150108/040ccf55/attachment.html>


More information about the Haskell-Cafe mailing list