[Haskell-beginners] lost a typeclass maybe?
Silent Leaf
silent.leaf0 at gmail.com
Fri Jun 30 08:56:35 UTC 2017
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 <tjakway at nyu.edu>:
> 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" <silent.leaf0 at gmail.com> 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 <silent.leaf0 at gmail.com>:
>>
>>> 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 <silent.leaf0 at gmail.com>:
>>>
>>>> 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 <silent.leaf0 at gmail.com>:
>>>>
>>>>> 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
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170630/2b595e60/attachment.html>
More information about the Beginners
mailing list