[Haskell-cafe] Lifting a value into a DataKind

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Wed Feb 8 05:43:17 UTC 2017


As a sample implementation of the current state that I'd like to
simplify, see https://github.com/erikd/fastpack/blob/master/bench/bench.hs
(specifically, the `compareFunc` usage and the definition of
`withLibrary`).

I've found myself writing similar patterns of late and wanted to try
and automate it a bit.  Specifically, it's the withLibrary function
I'm trying to work out how I could automatically generate for similar
types (as I've even written such type+function combinations in other
unrelated instances; I've found it a useful approach when I want to
select between typeclass instances).

On 8 February 2017 at 14:35, Richard Eisenberg <rae at cs.brynmawr.edu> wrote:
> I fear, though, that you'll need a big hammer to be able to do what you want. Could you draw out your example a bit, and then we can see what the smaller hammer might look like.
>
> Richard
>
>> On Feb 7, 2017, at 10:32 PM, Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com> wrote:
>>
>> Thanks for the suggestion; I think singletons is a bit of a large
>> hammer for a small bit of extra functionality I was thinking of adding
>> though (especially with people needing to use TH to make their
>> datatypes instances of SingI as well).
>>
>> On 8 February 2017 at 12:55, Richard Eisenberg <rae at cs.brynmawr.edu> wrote:
>>> The singletons library's `toSing` (or `withSing`) may be what you want. Note that if you use Proxy, you won't be able to make any runtime decisions on the choice of `b`.
>>>
>>> Richard
>>>
>>>> On Feb 7, 2017, at 6:55 PM, Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com> wrote:
>>>>
>>>> Is it possible to automatically lift an arbitrary value into a type?
>>>> i.e. I'm after a function of type `a -> Proxy (b :: a)`.
>>>>
>>>> More specifically, I'm wanting to be able to write a function that can
>>>> convert an Enum (e.g. Bool or Ord) into such a Proxy, so I can
>>>> actually write a function that looks like: `a -> (forall b. Proxy (b
>>>> :: a) -> r) -> r` and use the `a` type as a selector value (to e.g.
>>>> choose between type class instances).
>>>>
>>>> --
>>>> Ivan Lazar Miljenovic
>>>> Ivan.Miljenovic at gmail.com
>>>> http://IvanMiljenovic.wordpress.com
>>>> _______________________________________________
>>>> Haskell-Cafe mailing list
>>>> To (un)subscribe, modify options or view archives go to:
>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>>> Only members subscribed via the mailman list are allowed to post.
>>>
>>
>>
>>
>> --
>> Ivan Lazar Miljenovic
>> Ivan.Miljenovic at gmail.com
>> http://IvanMiljenovic.wordpress.com
>



-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list