[Haskell-cafe] "Casting" newtype to base type?

David McBride toad3k at gmail.com
Tue Jul 2 15:37:05 CEST 2013


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.basic at gmail.com> wrote:
>
>
> -------- Original Message  --------
> Subject: Re: [Haskell-cafe] "Casting" newtype to base type?
> From: Tom Ellis <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk>
> To: haskell-cafe at 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 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 (Show, Eq)
>>>
>>>
>>> getC_IO :: P -> IO String
>>> getC_IO p =
>>>    case getC p of
>>>      IOS a -> a
>>> getC_IO (P _ _ (IOS a)) = a
>>
>>
>> How about
>>
>>      unIOS :: IOS -> IO String
>>      unIOS (IOS a) = a
>>
>>      getC_IO :: P -> IO String
>>      getC_IO = unIOS . getC
>>
> Thanks for your answer.
> I had those two funcs, but thought there might be a shorter/prettier
> one-func one-liner. :-)
>
>
>> Tom
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list