[Haskell-cafe] (no subject)
Sun Apr 24 20:07:37 UTC 2016
>From int-e at gmx.de Sun Apr 24 21:13:18 2016
Date: Sun, 24 Apr 2016 21:13:18 +0200
From: Bertram Felgenhauer <bertram.felgenhauer at googlemail.com>
To: haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] Is it possible to make lazy combinators for IO?
Message-ID: <20160424191319.GA32509 at 24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f>
References: <CAMgWh9t4MbzbbdvnU8zz6Lm-p9Gtf2UO-+GaW=ofPsNLmt4aCA at mail.gmail.com>
<CAErCyQ-J+iYo2tXVs9S4VtGtuurFaNp=zsrY_58=7EeL7q0HVQ at mail.gmail.com>
<CAMgWh9s3+ksQOh52oU=azKcdLDyuFy2sYKPbz30xaXnTkLK9cw at mail.gmail.com>
<CAErCyQ8OVMF0fMDuxLpuvHimCt7RBijjzp1wEBMxRFyyyCXZVg at mail.gmail.com>
<CAMgWh9vsxijoCuNrMxeAZmVxML+A8iNUwpTy9Es1BF0z_+pryQ at mail.gmail.com>
<CAMgWh9tV_aq2=NkKZ79QZX6Xn6V953RwWoFqTeUMDggF0=ZZ+g at mail.gmail.com>
<CAErCyQ_zUqn53x1=g3RKDjQc3+GXfXkj1VvaTxo8ONPeTfym0A at mail.gmail.com>
<CAMgWh9s=0bAsjGEgGwSr8bPL6vDqNL8yyY=G+qANoz35G0NKuw at mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAMgWh9s=0bAsjGEgGwSr8bPL6vDqNL8yyY=G+qANoz35G0NKuw at mail.gmail.com>
User-Agent: Mutt/1.5.24 (2015-08-30)
Status: RO
Content-Length: 1283
Lines: 37
David Feuer wrote:
> What I'm looking for is more limited than lazy IO or unsafeInterleaveIO,
> but it seems quite possible that there's no way to get just what I'm
> looking for with the IO type proper using GHC's implementation of IO. Lazy
> IO allows evaluation to drive action. When a thunk is forced, it may
> trigger I/O (spooky action at a distance). What I'm talking about is
> separating what actions are performed from what values are calculated from
> them. Here's a partial concept which won't actually compile because of the
> lazy pattern matches:
>
> data MyIO a = forall b . MyIO (b -> a) (IO b)
> instance Functor MyIO where
> fmap f ~(MyIO t m) = MyIO (f . t) m
> instance Applicative MyIO where
> pure a = MyIO (const a) (pure ())
> MyIO t1 m1 <*> ~(MyIO t2 m2) =
> MyIO (\(r1, r2) -> t1 r1 (t2 r2)) ((,) <$> m1 <*> m2)
> instance Monad MyIO where
> ???
> instance MonadFix MyIO where
> ???
I believe that using this interface `unsafeInterleaveIO` could be
implemented as follows, making it just as powerful as lazy IO:
data Box a = Box a
unsafeInterleaveMyIO :: MyIO a -> MyIO a
unsafeInterleaveMyIO act = do
act' <- Box `fmap` act
return $ case act' of Box !r -> r
Have I missed anything?
Cheers,
Bertram
More information about the Haskell-Cafe
mailing list