[Haskell-cafe] casting a into Maybe a

2013-07-27 Thread Joerg Fritsch
If I have the following type signature transMit :: Serialize a = Socket - POSIXTime - KEY - Maybe a - TPSQ - TMap a - IO () And the function is called with transMit s now key newmsgs q m where newmsgs is whatever type a I get but _not_ a Maybe a then I get the error Could not deduce (a ~

Re: [Haskell-cafe] casting a into Maybe a

2013-07-27 Thread Niklas Hambüchen
Put a Just around it? transMit s now key (Just newmsgs) q m On Sat 27 Jul 2013 20:05:43 JST, Joerg Fritsch wrote: If I have the following type signature transMit :: Serialize a = Socket - POSIXTime - KEY - Maybe a - TPSQ - TMap a - IO () And the function is called with transMit s now key

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-06 Thread Ozgur Akgun
Hi Vlatko. On 2 July 2013 16:03, Vlatko Basic vlatko.ba...@gmail.com wrote: Is there a nicer way to extract the 'IO String' from 'IOS', without 'case' or without pattern matching the whole 'P'? You might enjoy the newtype package. http://hackage.haskell.org/package/newtype Hope this helps,

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread Vlatko Basic
of IOS a - a getC_IO (P _ _ (IOS a)) = a Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Malcolm Wallace malcolm.wall...@me.com To: vlatko.ba...@gmail.com Cc: Haskell-Cafe haskell-cafe@haskell.org Date: 01.07.2013 17:24 On 1 Jul 2013, at 16:07

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread Tom Ellis
On Tue, Jul 02, 2013 at 03:03:08PM +0200, Vlatko Basic wrote: Is there a nicer way to extract the 'IO String' from 'IOS', without 'case' or without pattern matching the whole 'P'? newtype IOS = IOS (IO String) data P = P { getA :: String, getB :: String, getC :: IOS } deriving

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread Vlatko Basic
Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk To: haskell-cafe@haskell.org Date: 02.07.2013 15:25 On Tue, Jul 02, 2013 at 03:03:08PM +0200, Vlatko Basic wrote: Is there a nicer way

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread David McBride
You could always just put it into your newtype: newtype IOS = IOS { unIOS :: IO String } On Tue, Jul 2, 2013 at 9:31 AM, Vlatko Basic vlatko.ba...@gmail.com wrote: Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Tom Ellis tom-lists

[Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Vlatko Basic
Hello Cafe! I had a (simplified) record data P = P { a :: String, b :: String, c :: IO String } deriving (Show, Eq) but to get automatic deriving of 'Show' and 'Eq' for 'data P' I have created 'newtype IOS' and its 'Show' and 'Eq' instances newtype IOS = IO String

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Frerich Raabe
Am 7/1/2013 5:07 PM, schrieb Vlatko Basic: to get automatic deriving of 'Show' and 'Eq' for 'data P' I have created 'newtype IOS' and its 'Show' and 'Eq' instances newtype IOS = IO String What you really want is newtype IOS = IOS (IO String) I.e. a IOS value wraps an IO String.

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Tom Ellis
On Mon, Jul 01, 2013 at 05:07:00PM +0200, Vlatko Basic wrote: Hello Cafe! I had a (simplified) record data P = P { a :: String, b :: String, c :: IO String } deriving (Show, Eq) but to get automatic deriving of 'Show' and 'Eq' for 'data P' I have created 'newtype

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Malcolm Wallace
On 1 Jul 2013, at 16:07, Vlatko Basic wrote: I had a (simplified) record data P = P { a :: String, b :: String, c :: IO String } deriving (Show, Eq) but to get automatic deriving of 'Show' and 'Eq' for 'data P' I have created 'newtype IOS' and its 'Show' and 'Eq'

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Vlatko Basic
Hi Wallace, yes, indeed. Now I see I mixed newtype with type in declaration, and forgot the first one is a constructor. Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Malcolm Wallace malcolm.wall...@me.com To: vlatko.ba...@gmail.com Cc

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Vlatko Basic
I'm experimenting. The IO field is just a helper field, so it shouldn't have any consequences. Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk To: haskell-cafe@haskell.org Date: 01.07.2013

Re: [Haskell-cafe] casting

2006-10-10 Thread Bulat Ziganshin
Hello Thomas, Monday, October 9, 2006, 3:47:05 PM, you wrote: constraints on its type. Rather than being just any type that is an instance of A, I want to do a runtime check and do something different it's a sort of problem that bites me many times when i start to wrote Streams library :)

[Haskell-cafe] casting

2006-10-09 Thread Thomas Conway
Hi All I'm having some difficulty with typeclasses. What I'm trying to do should be obvious, but it's still giving me trouble. I want to take a packaged item, and strengthen the constraints on its type. Rather than being just any type that is an instance of A, I want to do a runtime check and

Re: [Haskell-cafe] casting

2006-10-09 Thread Misha Aizatulin
Thomas Conway wrote: I'm having some difficulty with typeclasses. What I'm trying to do should be obvious, but it's still giving me trouble. I want to take a packaged item, and strengthen the constraints on its type. Rather than being just any type that is an instance of A, I want to do a

Re: [Haskell-cafe] casting

2006-10-09 Thread Thomas Conway
Thanks Misha Matthias. I now get what's going on. The mention of the word dictionary revealed it all. I've spent the last 7 years programming in C++, and had dynamic_cast firmly fixed in my head. I totally forgot that Fergus Henderson and I independently reinvented dictionary passing for the

Re: [Haskell-cafe] casting numerical types

2006-04-02 Thread Matthias Fischmann
Subject: Re: [Haskell-cafe] casting numerical types Arbitrary numerical types don't support division. (They're rings, not fields.) The (Fractional a) = [a] - a type is the best you can do. - Cale On 01/04/06, Matthias Fischmann [EMAIL PROTECTED] wrote: hi all, this should

Re: [Haskell-cafe] casting numerical types

2006-04-02 Thread Malcolm Wallace
Matthias Fischmann [EMAIL PROTECTED] writes: avg :: (FractionalOrIntegral a) = [a] - a avg xs = sum (map fromFractionalOrIntegral xs) / (fromIntegral (length xs)) Your condition is probably too strong. For one thing, there is no need to convert every element of the list being summed,

Re: [Haskell-cafe] casting numerical types

2006-04-02 Thread Matthias Fischmann
On Sun, Apr 02, 2006 at 10:53:02AM +0100, Malcolm Wallace wrote: To: haskell-cafe@haskell.org From: Malcolm Wallace [EMAIL PROTECTED] Date: Sun, 2 Apr 2006 10:53:02 +0100 Subject: Re: [Haskell-cafe] casting numerical types Matthias Fischmann [EMAIL PROTECTED] writes: avg

Re: [Haskell-cafe] casting numerical types

2006-04-01 Thread Cale Gibbard
Arbitrary numerical types don't support division. (They're rings, not fields.) The (Fractional a) = [a] - a type is the best you can do. - Cale On 01/04/06, Matthias Fischmann [EMAIL PROTECTED] wrote: hi all, this should be a quick one (for now I would be happy with a that's impossible,