lost a typeclass maybe?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

lost a typeclass maybe?

Silent Leaf
hi,

i keep trying to find something that feels terribly obvious but i can't make any link.

say i have a function of the following type:

foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]

is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).

i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!

is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).

especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: lost a typeclass maybe?

Silent Leaf
well, i sent once more my message too early by mistake.
when i say invent IO a b, i don't actually mean an IO type, i meant just, any type you can't manually unbox via pattern matching or otherwise.

2017-06-29 20:36 GMT+02:00 Silent Leaf <[hidden email]>:
hi,

i keep trying to find something that feels terribly obvious but i can't make any link.

say i have a function of the following type:

foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]

is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).

i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!

is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).

especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: lost a typeclass maybe?

Silent Leaf
ah, obviously, the first parameter is meant to be (i -> k i -> k i).
mind you my opaqueBimap looks very peculiar...
if i isolate half of f a b:
Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a)
Foo f fa fas = lift f fa fas
so maybe i'd need a BiApplicative?

2017-06-29 20:38 GMT+02:00 Silent Leaf <[hidden email]>:
well, i sent once more my message too early by mistake.
when i say invent IO a b, i don't actually mean an IO type, i meant just, any type you can't manually unbox via pattern matching or otherwise.

2017-06-29 20:36 GMT+02:00 Silent Leaf <[hidden email]>:
hi,

i keep trying to find something that feels terribly obvious but i can't make any link.

say i have a function of the following type:

foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]

is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).

i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!

is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).

especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: lost a typeclass maybe?

Silent Leaf
hey it does seem to exist, so that would be

foo :: (BiApplicative f) :: (i -> k i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
foo f fab fkakb = bipure f f <<$>> fab <<*>> fkakb

pretty neat. i'm not sure the <<$>> operator exist, but the `ap` one does apparently.
however i'm not sure that many people use BiApplicative ^^ But hey why not.

don't pay attention to my code here, it's terribly typoed, i have no idea why i put the uppercase on the function Foo...

2017-06-29 20:44 GMT+02:00 Silent Leaf <[hidden email]>:
ah, obviously, the first parameter is meant to be (i -> k i -> k i).
mind you my opaqueBimap looks very peculiar...
if i isolate half of f a b:
Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a)
Foo f fa fas = lift f fa fas
so maybe i'd need a BiApplicative?

2017-06-29 20:38 GMT+02:00 Silent Leaf <[hidden email]>:
well, i sent once more my message too early by mistake.
when i say invent IO a b, i don't actually mean an IO type, i meant just, any type you can't manually unbox via pattern matching or otherwise.

2017-06-29 20:36 GMT+02:00 Silent Leaf <[hidden email]>:
hi,

i keep trying to find something that feels terribly obvious but i can't make any link.

say i have a function of the following type:

foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]

is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).

i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!

is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).

especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: lost a typeclass maybe?

Thomas Jakway
For what it's worth I think Bifunctors are more useful than one might think given the lack of attention they get.

On Jun 29, 2017 2:51 PM, "Silent Leaf" <[hidden email]> wrote:
hey it does seem to exist, so that would be

foo :: (BiApplicative f) :: (i -> k i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
foo f fab fkakb = bipure f f <<$>> fab <<*>> fkakb

pretty neat. i'm not sure the <<$>> operator exist, but the `ap` one does apparently.
however i'm not sure that many people use BiApplicative ^^ But hey why not.

don't pay attention to my code here, it's terribly typoed, i have no idea why i put the uppercase on the function Foo...

2017-06-29 20:44 GMT+02:00 Silent Leaf <[hidden email]>:
ah, obviously, the first parameter is meant to be (i -> k i -> k i).
mind you my opaqueBimap looks very peculiar...
if i isolate half of f a b:
Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a)
Foo f fa fas = lift f fa fas
so maybe i'd need a BiApplicative?

2017-06-29 20:38 GMT+02:00 Silent Leaf <[hidden email]>:
well, i sent once more my message too early by mistake.
when i say invent IO a b, i don't actually mean an IO type, i meant just, any type you can't manually unbox via pattern matching or otherwise.

2017-06-29 20:36 GMT+02:00 Silent Leaf <[hidden email]>:
hi,

i keep trying to find something that feels terribly obvious but i can't make any link.

say i have a function of the following type:

foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]

is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).

i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!

is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).

especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: lost a typeclass maybe?

Silent Leaf
Good to know, thanks :) Then i won't automatically doubt my program structure if one day i end up needing it.

2017-06-29 23:05 GMT+02:00 Thomas Jakway <[hidden email]>:
For what it's worth I think Bifunctors are more useful than one might think given the lack of attention they get.

On Jun 29, 2017 2:51 PM, "Silent Leaf" <[hidden email]> wrote:
hey it does seem to exist, so that would be

foo :: (BiApplicative f) :: (i -> k i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
foo f fab fkakb = bipure f f <<$>> fab <<*>> fkakb

pretty neat. i'm not sure the <<$>> operator exist, but the `ap` one does apparently.
however i'm not sure that many people use BiApplicative ^^ But hey why not.

don't pay attention to my code here, it's terribly typoed, i have no idea why i put the uppercase on the function Foo...

2017-06-29 20:44 GMT+02:00 Silent Leaf <[hidden email]>:
ah, obviously, the first parameter is meant to be (i -> k i -> k i).
mind you my opaqueBimap looks very peculiar...
if i isolate half of f a b:
Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a)
Foo f fa fas = lift f fa fas
so maybe i'd need a BiApplicative?

2017-06-29 20:38 GMT+02:00 Silent Leaf <[hidden email]>:
well, i sent once more my message too early by mistake.
when i say invent IO a b, i don't actually mean an IO type, i meant just, any type you can't manually unbox via pattern matching or otherwise.

2017-06-29 20:36 GMT+02:00 Silent Leaf <[hidden email]>:
hi,

i keep trying to find something that feels terribly obvious but i can't make any link.

say i have a function of the following type:

foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]

is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).

i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!

is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).

especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Loading...