marrenarre 2017-02-18 18:52:59
Hey. I'm a beginner but maybe I can ask here since no response in the beginner channel and I heard this channel is beginner friendly sometimes too, and it seems kinda quiet now anyway.
marrenarre 2017-02-18 18:54:08
> liftA2 (:) (Right 3) (Left [5])
lambdabot 2017-02-18 18:54:17
Left [5]
marrenarre 2017-02-18 18:54:21
> liftA2 (:) (Left 3) (Right [5])
lambdabot 2017-02-18 18:54:24
Left 3
marrenarre 2017-02-18 18:54:27
How can it be that the contained value is only a list in the first case?
c_wraith 2017-02-18 18:55:14
the Applicative instance for Either considers Left values to be failures
c_wraith 2017-02-18 18:55:25
And it short-circuits any further evaluation if it finds one
c_wraith 2017-02-18 18:55:57
If it encounters any Left, it just returns that left
c_wraith 2017-02-18 18:56:31
> liftA2 (:) (Left 5) (Right "Hello, world")
lambdabot 2017-02-18 18:56:33
Left 5
c_wraith 2017-02-18 18:56:53
The only time the lifted function would actually be applied is if both arguments are Right
dramforever_ 2017-02-18 18:59:34
marrenarre: You can see why by subsituting the definitions in
dramforever_ 2017-02-18 18:59:42
That's how Haskell works basically
marrenarre 2017-02-18 19:06:10
Oh right.
marrenarre 2017-02-18 19:07:10
> liftA2 (:) (Left 3 :: Either Integer Integer) (Left [5])
lambdabot 2017-02-18 19:07:13
error:
lambdabot 2017-02-18 19:07:13
• Couldn't match type '[Integer]' with 'Integer'
lambdabot 2017-02-18 19:07:13
Expected type: Either Integer [Integer]
marrenarre 2017-02-18 19:07:38
> liftA2 (:) (Left 3) (Left [5])
lambdabot 2017-02-18 19:07:40
error:
lambdabot 2017-02-18 19:07:40
• Ambiguous type variable 't0' arising from a use of 'show_M306146079492...
lambdabot 2017-02-18 19:07:40
prevents the constraint '(Show t0)' from being solved.
marrenarre 2017-02-18 19:08:52
I meant I kinda know how liftA2 works but it seems like sometimes when two expressions should have the same type one of them gives a list and the other one doesn't.
marrenarre 2017-02-18 19:08:55
I mean*
marrenarre 2017-02-18 19:09:22
And I'm thinking "How can they have different types?".
marrenarre 2017-02-18 19:12:56
I think I get it though. They can have different types because the Left and Right literals only imply one type argument each to the Either type constructor. That's why it doesn't work when I have two Left value constructors that I give values of different types.
marrenarre 2017-02-18 19:15:08
Hmm that makes sense and seems to work for me in GHCi. I think I was just messing something up before and that's why I got confused. I realise the two I wrote before that didn't error can have different types.
marrenarre 2017-02-18 19:16:05
(Anyone wanna agree/disagree?)
c_wraith 2017-02-18 19:18:33
marrenarre: that sounds right
ClaudiusMaximus 2017-02-18 19:18:44
marrenarre: the Applicative instance is for Either e :: * -> * with e fixed across the whole computation, only the a in Either e a :: * can change
MarcelineVQ 2017-02-18 19:24:33
marrenarre: the type of liftA2 is liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c using ClaudiusMaximus's example above let's assign Int to `e`
MarcelineVQ 2017-02-18 19:24:52
substituting (Either Int) for f would give us a liftA2 that looks like liftA2 :: (a -> b -> c) -> Either Int a -> Either Int b -> Either Int c which may make it clearer as to why liftA2 (:) (Left 3) (Left [5]) was an error
abhiroop 2017-02-18 19:33:27
Has anyone used ekmett's trifecta library
abhiroop 2017-02-18 19:33:45
when i try to do cabal install trifecta-1.5.2
abhiroop 2017-02-18 19:34:12
I get the following error in blaze-markup- one of its dependencies
abhiroop 2017-02-18 19:34:12
There are files missing in the 'blaze-markup-0.7.1.0@blaze_IswqgMcsaFk6TfFYttEfHj' package,
abhiroop 2017-02-18 19:34:24
Any idea how I go about fixing?
marrenarre 2017-02-18 19:36:20
MarcelineVQ: Yeah, I mean I knew that shouldn't be right, it's just I forgot that the ones that did work should work. In my head I imagined that the compiler would want them to have the same type (since I was thinking of them simultaneously) but obviously that's not the case.
marrenarre 2017-02-18 19:37:12
I mean `liftA2 (:) (Right 3) (Left [5])` and `liftA2 (:) (Left 3) (Right [5])`.
marrenarre 2017-02-18 19:37:58
(So I was confused as to why both of those work, but I get it now.)
marrenarre 2017-02-18 19:38:33
c_wraith, ClaudiusMaximus, MarcelineVQ: Thanks!!
shinX 2017-02-18 19:45:01
$/names #haskell