
Given a class Foo:
class Foo f where> bar :: f -> Bool> baz :: f -> Char -> Int does the record type Foo' data Foo' = Foo' {> bar' :: Bool,> baz' :: Char -> Int> }> > instance Foo Foo' where> bar = bar'> baz = baz' where the fields of the record Foo' are just implementations of the functions of Foo have any special name? In some sense it's a canonical instance of Foo; we could trivially write a universal toFoo' :: Foo f => f -> Foo' function. I ran across this pattern and wondered whether it was useful enough to have received a name. It vaguely resembles a typeclass dictionary or a vtable in an OOP language. --Eric

On 2015-03-08 12:11 PM, Eric wrote:
In some sense it's a canonical instance of Foo; we could trivially write a universal
toFoo' :: Foo f => f -> Foo'
function.
Choose one: Foo' is a free Foo Foo' is a limit of the diagram of Foo Foo' is a terminal object of the [sub]category of Foo

Albert Y. C. Lai wrote:
On 2015-03-08 12:11 PM, Eric wrote:
In some sense it's a canonical instance of Foo; we could trivially write a universal
toFoo' :: Foo f => f -> Foo'
function.
Choose one:
Foo' is a free Foo
Foo' is a limit of the diagram of Foo
Foo' is a terminal object of the [sub]category of Foo
Interesting. Is the last variant how "free <whatever>" is usually defined? Or is it a coincidence that the two, well, coincide here? I remember I have seen other definitions that looked a lot less easy to understand. Cheers Ben

On 2015-03-09 11:26 AM, Ben Franksen wrote:
Albert Y. C. Lai wrote:
Choose one:
Foo' is a free Foo
Foo' is a limit of the diagram of Foo
Foo' is a terminal object of the [sub]category of Foo
Interesting. Is the last variant how "free <whatever>" is usually defined? Or is it a coincidence that the two, well, coincide here? I remember I have seen other definitions that looked a lot less easy to understand.
I have not checked, and too lazy to. The usual "free" is the less-easy-to-understand one: you need a forgetful functor, then you need its left adjoint, and you call it your free functor. Then the target objects hit by the free functor are the free things.
participants (3)
-
Albert Y. C. Lai
-
Ben Franksen
-
Eric