a transformation of a function into a corresponding function in a more general context.
Questions tagged [lifting]
84 questions
6
votes
1 answer
Typeclass tricks for generalized multi-parameter function lifting
I want to lift a Haskell function into in a higher-order lambda calculus encoding. This is taken almost verbatim from Oleg's Typed Tagless Final encoding.
class Lam r where
emb :: a -> r a
(^) :: r (r a -> r a) -> (r a -> r a)
lam :: (r a -> r…

J. Abrahamson
- 72,246
- 9
- 135
- 180
5
votes
2 answers
How to implement a generic lift function for monads?
I have a bunch of arity aware lift functions:
const chain = f => xs =>
xs.reduce((acc, x) => acc.concat(f(x)), []);
const of = x => [x];
const add = (x, y) => x + y;
const liftM2 = (chain, of) => f => m1 => m2 =>
chain(x => chain(y…
user5536315
4
votes
1 answer
Are the liftM functions deprived of their monadic essence?
The difference between monad and applicative is that the former can choose the next computation depending on a previous result:
(\x -> if x == 1 then (\_ -> []) else (\y -> (\z -> \w -> [x,y,z]) =<< sqr) =<< (+1)) =<< (+1) $ 0
-- …
user5536315
4
votes
1 answer
liftM in ghci: why is there such difference?
When I define such functions inside ghci:
> :m Control.Monad
> let f n = n+1
> let g = liftM f
they work well:
> g $ Just 2
> Just 3
> g $ [1,2]
> [2,3]
But when I define the same functions in file (probl.hs):
import Control.Monad
f :: Integer…

Vladimir
- 541
- 2
- 8
4
votes
4 answers
Applying lifted functions to tuples (of arbitrary length) in Haskell
Is there any explanation for why a lifted function, when applied to 2-tuple, only applies to the 2nd entry:
f x = x + 1
f <$> (2,2)
// -> (2,3)
On the other hand, tuples of any other length than 2 return errors.
Also
:t f <$>
returns an…

Dmitri Zaitsev
- 13,548
- 11
- 76
- 110
4
votes
1 answer
Monad Transformers lift
I was just looking into monad transformers in real world Haskell.
The book said that to make something a monad transformer, you need to make it an instance of the MonadTrans type class.
So the book defined a new Transformer, the MaybeT m a…

Yusuf
- 491
- 2
- 8
4
votes
1 answer
Transformation of (a -> IO b) to IO (a -> b)
I have several data types in an IO context like:
a :: IO String
b :: IO FilePath
c :: String -> IO String
I want to put them all together in one data object like:
data Configdata = Configdata String FilePath (String -> String)
So I don't have to…

F. Böller
- 4,194
- 2
- 20
- 32
4
votes
2 answers
Flatten monad stack
So I have this sort of code all over my first serious haskell project:
f :: (MonadTrans t) => ExceptT () (t (StateT A B)) C
f = do mapExceptT lift $ do
lift $ do
...
lift $ do
...
r <- ...
...
…

jakubdaniel
- 2,233
- 1
- 13
- 20
3
votes
4 answers
Converting f(x) into f([x]) using decorator in python
class foo(object):
def __init__(self,f):
self.f = f
def __call__(self,args_list):
def wrapped_f(args_list):
return [self.f(*args) for args in args_list]
return…

Pratik Deoghare
- 35,497
- 30
- 100
- 146
3
votes
1 answer
Haskell Monads and the liftIO I don't get it
Hello community thank you for your time.
I have an error and I am not sure what the error is, but what I think the problem is:
There is no IO transformer from ext-1.2.4.1:Data.Text.Internal.Lazy.Text IO) to Web.Scotty.Internal.Types.ScottyT.
But I…

peni4142
- 426
- 1
- 7
- 26
3
votes
1 answer
How to rewrite ado notation as general Applicative lifting, respecting evaluation order?
There seems to be a difference in the evaluation order of applicative do notation / ado vs. applicative lifting via <$>/map on the first argument, and <*>/apply for remaining arguments.
At least, this is what I have read so far and what is…

A_blop
- 792
- 2
- 11
3
votes
1 answer
Lifting function to Option
Is there a way to lift a simple function, like this
fn add(a:i32, b:i32) -> i32 {a+b}
to operate on Option (or any other monadic type), similar to how one would use Applicative in Haskell
I'm aware of this solution:
pub fn add(a: Option, b:…

dark_ruby
- 7,646
- 7
- 32
- 57
3
votes
3 answers
Lifting a value in the State monad in Haskell
I am writing a Sudoku generator/solver in Haskell as a learning exercise.
My solve function takes in a UArray but returns a State Int (UArray ...) so that it can also return the maximum difficulty level that it found while solving.
This is my…

Ralph
- 31,584
- 38
- 145
- 282
3
votes
3 answers
Why does this expression have a valid type?
Banging around in ghci, I happened to notice that the expression (*) 1 [1..5] apparently has a valid type.
:t (*) 1 [1..5]
(*) 1 [1..5] :: (Enum t, Num [t], Num t) => [t]
Apparently it is a list with several type constraints, including Num [t]…

mherzl
- 5,624
- 6
- 34
- 75
3
votes
2 answers
directly applying lift function not give expected function
Below are the two partial function that are expected to perform sme tasks but defined in diffrent ways.
val pf1 : PartialFunction[String, String] = {
case s : String if (s != null) => s.toUpperCase()
}
//> pf1 : PartialFunction[String,String] =…

mogli
- 1,549
- 4
- 29
- 57