Re: [Haskell-cafe] How to "instance MonadIO Identity"?

2010-12-27 Thread Magicloud Magiclouds
Wow, this explains a lot. Thanks.

On Tue, Dec 28, 2010 at 2:05 PM, Antoine Latter  wrote:
> There are a couple of ways to handle this - either call
> getSystemEncoding on the outside, before calling 'runWriter', and then
> pass it in to your writer computation, or use 'WriterT IO' instead of
> 'Writer'.
>
> That would be something like:
>
> main = do
>  result <- runWriterT ( computation involving 'tell' and 'liftIO')
>  ( computation using result)
>
> The error message in your case can be difficult to understand - the
> 'Writer' type is a synonym for the type 'WriterT Identity'. Since none
> of these types involve IO, then liftIO can't be used.
>
> Antoine
>
>
> On Tue, Dec 28, 2010 at 12:47 AM, Magicloud Magiclouds
>  wrote:
>>  Ah, that is a bad news.
>>  I am using Control.Monad.Writer and Data.Encoding. Code like (not 
>> compilable)
>> 43|instance WithMessage String where
>> 44|  append s = (liftIO $ getSystemEncoding) >>= (\e -> tell $
>> encodeLazyByteString e s)
>>  May I know how to make this work?
>>
>> 2010/12/28 Michael Snoyman :
>>> The only way to create such an instance would be with unsafePerformIO,
>>> which in this case would be a Very Bad Idea (tm).
>>>
>>> Michael
>>>
>>> On Tue, Dec 28, 2010 at 7:29 AM, Magicloud Magiclouds
>>>  wrote:
 Hi,
  From another thread in this list, I got code as:
> instance MonadIO Identity where
>     liftIO = id
  Well, it does not work for me as:
 Message.hs:22:12:
    Couldn't match expected type `Identity a' with actual type `IO a'
    Expected type: IO a -> Identity a
      Actual type: IO a -> IO a
    In the expression: id
    In an equation for `liftIO': liftIO = id
 --
 竹密岂妨流水过
 山高哪阻野云飞

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

>>>
>>
>>
>>
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>



-- 
竹密岂妨流水过
山高哪阻野云飞

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to "instance MonadIO Identity"?

2010-12-27 Thread Antoine Latter
There are a couple of ways to handle this - either call
getSystemEncoding on the outside, before calling 'runWriter', and then
pass it in to your writer computation, or use 'WriterT IO' instead of
'Writer'.

That would be something like:

main = do
  result <- runWriterT ( computation involving 'tell' and 'liftIO')
  ( computation using result)

The error message in your case can be difficult to understand - the
'Writer' type is a synonym for the type 'WriterT Identity'. Since none
of these types involve IO, then liftIO can't be used.

Antoine


On Tue, Dec 28, 2010 at 12:47 AM, Magicloud Magiclouds
 wrote:
>  Ah, that is a bad news.
>  I am using Control.Monad.Writer and Data.Encoding. Code like (not compilable)
> 43|instance WithMessage String where
> 44|  append s = (liftIO $ getSystemEncoding) >>= (\e -> tell $
> encodeLazyByteString e s)
>  May I know how to make this work?
>
> 2010/12/28 Michael Snoyman :
>> The only way to create such an instance would be with unsafePerformIO,
>> which in this case would be a Very Bad Idea (tm).
>>
>> Michael
>>
>> On Tue, Dec 28, 2010 at 7:29 AM, Magicloud Magiclouds
>>  wrote:
>>> Hi,
>>>  From another thread in this list, I got code as:
 instance MonadIO Identity where
     liftIO = id
>>>  Well, it does not work for me as:
>>> Message.hs:22:12:
>>>    Couldn't match expected type `Identity a' with actual type `IO a'
>>>    Expected type: IO a -> Identity a
>>>      Actual type: IO a -> IO a
>>>    In the expression: id
>>>    In an equation for `liftIO': liftIO = id
>>> --
>>> 竹密岂妨流水过
>>> 山高哪阻野云飞
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>
>
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to "instance MonadIO Identity"?

2010-12-27 Thread Michael Snoyman
Well, you *could* use unsafePerformIO on getSystemEncoding, though I'm
not familiar with getSystemEncoding, so I can't tell you whether this
is an acceptable usage of unsafePerformIO.

On Tue, Dec 28, 2010 at 7:47 AM, Magicloud Magiclouds
 wrote:
>  Ah, that is a bad news.
>  I am using Control.Monad.Writer and Data.Encoding. Code like (not compilable)
> 43|instance WithMessage String where
> 44|  append s = (liftIO $ getSystemEncoding) >>= (\e -> tell $
> encodeLazyByteString e s)
>  May I know how to make this work?
>
> 2010/12/28 Michael Snoyman :
>> The only way to create such an instance would be with unsafePerformIO,
>> which in this case would be a Very Bad Idea (tm).
>>
>> Michael
>>
>> On Tue, Dec 28, 2010 at 7:29 AM, Magicloud Magiclouds
>>  wrote:
>>> Hi,
>>>  From another thread in this list, I got code as:
 instance MonadIO Identity where
 liftIO = id
>>>  Well, it does not work for me as:
>>> Message.hs:22:12:
>>>Couldn't match expected type `Identity a' with actual type `IO a'
>>>Expected type: IO a -> Identity a
>>>  Actual type: IO a -> IO a
>>>In the expression: id
>>>In an equation for `liftIO': liftIO = id
>>> --
>>> 竹密岂妨流水过
>>> 山高哪阻野云飞
>>>
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>
>
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to "instance MonadIO Identity"?

2010-12-27 Thread Magicloud Magiclouds
  Ah, that is a bad news.
  I am using Control.Monad.Writer and Data.Encoding. Code like (not compilable)
43|instance WithMessage String where
44|  append s = (liftIO $ getSystemEncoding) >>= (\e -> tell $
encodeLazyByteString e s)
  May I know how to make this work?

2010/12/28 Michael Snoyman :
> The only way to create such an instance would be with unsafePerformIO,
> which in this case would be a Very Bad Idea (tm).
>
> Michael
>
> On Tue, Dec 28, 2010 at 7:29 AM, Magicloud Magiclouds
>  wrote:
>> Hi,
>>  From another thread in this list, I got code as:
>>> instance MonadIO Identity where
>>>     liftIO = id
>>  Well, it does not work for me as:
>> Message.hs:22:12:
>>    Couldn't match expected type `Identity a' with actual type `IO a'
>>    Expected type: IO a -> Identity a
>>      Actual type: IO a -> IO a
>>    In the expression: id
>>    In an equation for `liftIO': liftIO = id
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>



-- 
竹密岂妨流水过
山高哪阻野云飞

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to "instance MonadIO Identity"?

2010-12-27 Thread Michael Snoyman
The only way to create such an instance would be with unsafePerformIO,
which in this case would be a Very Bad Idea (tm).

Michael

On Tue, Dec 28, 2010 at 7:29 AM, Magicloud Magiclouds
 wrote:
> Hi,
>  From another thread in this list, I got code as:
>> instance MonadIO Identity where
>> liftIO = id
>  Well, it does not work for me as:
> Message.hs:22:12:
>Couldn't match expected type `Identity a' with actual type `IO a'
>Expected type: IO a -> Identity a
>  Actual type: IO a -> IO a
>In the expression: id
>In an equation for `liftIO': liftIO = id
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to "instance MonadIO Identity"?

2010-12-27 Thread Magicloud Magiclouds
Hi,
  From another thread in this list, I got code as:
> instance MonadIO Identity where
> liftIO = id
  Well, it does not work for me as:
Message.hs:22:12:
Couldn't match expected type `Identity a' with actual type `IO a'
Expected type: IO a -> Identity a
  Actual type: IO a -> IO a
In the expression: id
In an equation for `liftIO': liftIO = id
-- 
竹密岂妨流水过
山高哪阻野云飞

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe