a transformation of a function into a corresponding function in a more general context.
Questions tagged [lifting]
77 questions
266
votes
4 answers
What is "lifting" in Scala?
Sometimes when I read articles in the Scala ecosystem I read the term "lifting" / "lifted". Unfortunately, it is not explained what that exactly means. I did some research, and it seems that lifting has something to do with functional values or…
![](../../users/profiles/573215.webp)
user573215
- 4,437
- 5
- 20
- 25
28
votes
1 answer
Is it possible to implement liftM2 in Scala?
In Haskell, liftM2 can be defined as:
liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 f m1 m2 = do
x1 <- m1
x2 <- m2
return $ f x1 x2
I'd like to translate this to Scala. My first attempt was the following:
def…
![](../../users/profiles/1011414.webp)
mergeconflict
- 7,861
- 31
- 63
28
votes
4 answers
C# Lambda performance issues/possibilities/guidelines
I'm testing performance differences using various lambda expression syntaxes. If I have a simple method:
public IEnumerable- GetItems(int point)
{
return this.items.Where(i => i.IsApplicableFor(point));
}
then there's some variable lifting…
![](../../users/profiles/75642.webp)
Robert Koritnik
- 97,460
- 50
- 267
- 388
26
votes
3 answers
Can't wrap my head around "lift" in Ramda.js
Looking at the source for Ramda.js, specifically at the "lift" function.
lift
liftN
Here's the given example:
var madd3 = R.lift(R.curry((a, b, c) => a + b + c));
madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
So the first number…
![](../../users/profiles/3316036.webp)
diplosaurus
- 2,334
- 4
- 19
- 44
22
votes
1 answer
How do I break down a chain of member access expressions?
The Short Version (TL;DR):
Suppose I have an expression that's just a chain of member access operators:
Expression> e = x => x.foo.bar.baz;
You can think of this expression as a composition of sub-expressions, each comprising one…
![](../../users/profiles/399649.webp)
Justin Morgan
- 27,557
- 11
- 71
- 100
19
votes
1 answer
Lifting a higher order function in Haskell
I'm trying to construct a function of type:
liftSumthing :: ((a -> m b) -> m b) -> (a -> t m b) -> t m b
where t is a monad transformer. Specifically, I'm interested in doing this:
liftSumthingIO :: MonadIO m => ((a -> IO b) -> IO b) -> (a -> m b)…
![](../../users/profiles/1204186.webp)
zeus
- 238
- 1
- 7
10
votes
1 answer
Tidying up Monads - turning application of a monad transformer into newtype monad
I am trying to take e.g. ExceptT a (StateT A M), for some concrete type A and monad M, and wrap them up into my new custom monads.
First I identified that StateT A M appears often in other contexts and thus I decided it would be best to wrap that…
![](../../users/profiles/1027321.webp)
jakubdaniel
- 2,241
- 1
- 11
- 20
9
votes
2 answers
lift Either to ExceptT automatically
Let's say I have this (arguably mislead) piece of code laying around:
import System.Environment (getArgs)
import Control.Monad.Except
parseArgs :: ExceptT String IO User
parseArgs =
do
args <- lift getArgs
case safeHead args of
Just…
![](../../users/profiles/600545.webp)
romeovs
- 5,205
- 7
- 37
- 69
7
votes
2 answers
When exactly is lifting needed in monad transformers?
I am learning monad transformers and I am confused about when using lift is necessary.
Assume that I have the following code (It's not doing anything interesting, just the simplest I could come with for demonstration).
foo :: Int -> State Int…
![](../../users/profiles/1747134.webp)
user1747134
- 1,982
- 15
- 19
7
votes
2 answers
How come I can pass functions to a lifted R.divide?
Given the following:
var average = R.lift(R.divide)(R.sum, R.length)
How come this works as a pointfree implementation of average? I don't understand why I can pass R.sum and R.length when they are functions and therefore, I cannot map the lifted…
![](../../users/profiles/1726359.webp)
Chad
- 1,761
- 5
- 21
- 35
7
votes
3 answers
What are the steps for deducing this pointfree code?
I was reviewing some code and came across the following gem, which I'd wager is a copy-paste of pointfree output:
(I thought the following would more appropriate than the usual foo/bar for this particular question :P)
import Control.Monad…
![](../../users/profiles/4089188.webp)
iceman
- 1,880
- 1
- 13
- 21
7
votes
1 answer
Confusion with 'lifting' functions in Scala
In the book Functional Programming In Scala, there's an example of 'Lift' where a function with type A => B is promoted to Option[A] => Option[B].
This is how lift is implemented:
def lift[A,B](f: A => B):Option[A] => Option[B] = _ map f
I have a…
![](../../users/profiles/207072.webp)
sc_ray
- 7,385
- 9
- 59
- 94
7
votes
1 answer
Transformation under Transformers
I'm having a bit of difficulty with monad transformers at the moment. I'm defining a few different non-deterministic relations which make use of transformers. Unfortunately, I'm having trouble understanding how to translate cleanly from one…
![](../../users/profiles/754864.webp)
tvynr
- 143
- 4
6
votes
1 answer
In Haskell, are there aliases for (liftM . liftM), (liftM . liftM . liftM), etc?
In Haskell, is there any alias for (liftM . liftM), (liftM . liftM . liftM) etc?
So that I don't have to be so verbose, e.g.:
(liftM . liftM) (+ 1) [Just 1, Just 2] = [Just 2, Just 3]
(liftM2 . liftM2) (+) [Just 1] [Just 2] = [Just 3]
![](../../users/profiles/1120410.webp)
Lay González
- 2,765
- 16
- 34
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…
![](../../users/profiles/476408.webp)
J. Abrahamson
- 64,404
- 8
- 128
- 172