Questions tagged [lifting]

a transformation of a function into a corresponding function in a more general context.

84 questions
287
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…
user573215
  • 4,679
  • 5
  • 22
  • 25
29
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…
diplosaurus
  • 2,538
  • 5
  • 25
  • 53
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…
mergeconflict
  • 8,156
  • 34
  • 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…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
23
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…
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)…
zeus
  • 238
  • 1
  • 7
10
votes
3 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…
romeovs
  • 5,785
  • 9
  • 43
  • 74
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…
jakubdaniel
  • 2,233
  • 1
  • 13
  • 20
7
votes
1 answer

Difference between lifting and higher order functions

I usually hear the term lifting, when people are talking about map, fold, or bind, but isn't basically every higher order function some kind of lifting? Why can't filter be a lift from a -> Bool to [a] -> [a], heck even the bool function (which…
hgiesel
  • 5,430
  • 2
  • 29
  • 56
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…
Chad
  • 2,041
  • 6
  • 25
  • 39
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…
iceman
  • 2,020
  • 2
  • 17
  • 24
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…
sc_ray
  • 7,803
  • 11
  • 63
  • 100
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…
tvynr
  • 143
  • 4
6
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…
user1747134
  • 2,374
  • 1
  • 19
  • 26
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]
Lay González
  • 2,901
  • 21
  • 41
1
2 3 4 5 6