<div dir="ltr">My "solution" is a lot less interesting<div><br></div><div>lift1 = lift</div><div>lift2 = lift . lift1</div><div>lift3 = lift . lift2</div><div>lift4 = lift . lift3</div><div>lift5 = lift . lift4</div>

<div><br></div><div>What you want seemingly requires dependent types, because the result type depends on the Int that you pass in. Haskell is not well equipped to handle this, though you could probably whip up some Template Haskell to get the job done for cases where the Int can be determined at compile time.</div>

<div><br></div></div><div class="gmail_extra"><br clear="all"><div>-- Dan Burton</div>
<br><br><div class="gmail_quote">On Wed, Oct 16, 2013 at 2:06 PM, Wvv <span dir="ltr"><<a href="mailto:vitea3v@rambler.ru" target="_blank">vitea3v@rambler.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I try to write a function "liftN", but I'm not satisfied with result.<br>
<br>
lift :: (MonadTrans t) => Monad m => m a -> t m a<br>
<br>
liftN n<br>
š š | n < 1 š š š = error "liftN: n<1"<br>
š š | n == 1 š š = lift<br>
š š | otherwise = lift . (liftN (n-1))<br>
<br>
1) I know(?), that it is impossible to write liftN now: typechecker can't<br>
decide which signature it is.<br>
2) Main reason is finite recursive constraint<br>
<br>
3) Let's think, it is possible to write<br>
Main candidates: promoted data and data-kinds<br>
<br>
For example,<br>
lift . lift . lift<br>
š :: (Monad (t1 (t2 m)), Monad (t2 m), Monad m, MonadTrans t,<br>
š š š MonadTrans t1, MonadTrans t2) =><br>
š š šm a -> t (t1 (t2 m)) a<br>
<br>
My best solution looks like:<br>
<br>
data MT = M | T Int MT<br>
liftN :: forall tm. ( forall x n.<br>
š š š š š š š š š šMonad 'M, Monad (x :: MT),<br>
š š š š š š š š š šMonadTrans ('T n),<br>
š š š š š) => Int -> 'M a -> š('T 0) (tm :: MT) a<br>
liftN n<br>
š š š| n < 1 š š = error "liftN: šn < 1"<br>
š š š| n == 1 š š= lift<br>
š š š| otherwise = lift . (liftN (n-1))<br>
<br>
<br>
Am I miss something?<br>
I think this function could look much prettier.<br>
But I don't know how.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://haskell.1045720.n5.nabble.com/liftN-tp5738612.html" target="_blank">http://haskell.1045720.n5.nabble.com/liftN-tp5738612.html</a><br>
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>