Interlinking - Rib

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

In my private 'quantified self', I'm coming across the same use case as yours @Joel McCracken. That is, being able to link from one file to another, while not falling back to url strings. Ideally I want to be able to directly refer to a Source type, but that doesn't seem practical. So thinking of ways ...

Joel McCracken

the way I am doing it now is that a single source basically defines a number of links that are avialable to it

Joel McCracken

so after each source is parsed

Joel McCracken

the links from each are aggregated

Joel McCracken

then, those links are used in the rendering step

Sridhar Ratnakumar

If a document links to /foo/bar - how do you check that /foo/bar refers to one of the other documents?

Joel McCracken

well, what I have now is fairly limited in some ways

Joel McCracken

every document has a top level name (the filename - extension) and aliases

Joel McCracken

i can link to in another doc via

Sridhar Ratnakumar

Ideally I want to apply Haskell's "make illegal states non-representable" to interlinking too. This is done nicely with obelisk-routes (using GADTs)

Joel McCracken

<link to="glossary">Go to glossary</link>

Joel McCracken

yeah, this si all done at runtime

Joel McCracken

i';d have to do a lot more metaprogrammign to make it available at compiletime

Sridhar Ratnakumar

in my case, the 'metadata' lives in Haskell - so I can use haskell values directly.

Joel McCracken

the thing is, its always build then immediate run

Joel McCracken

you'll have to do some metaprogramming though i think

Joel McCracken

to generate types from the data

Joel McCracken

so that your routes are typesafe

Joel McCracken

well i dunno maybe not

Sridhar Ratnakumar

I'm beginning to have hierarchical ADTs when defining pages with hierarchy: eg:

data Page
  = Page_Index
  | Page_Food (Html ())
  | Page_TowardsPCE
  | Page_Journal JournalPage
  deriving (Generic)

data JournalPage
  = JournalPage_Index [Source MMark]
  | JournalPage_Entry (Source MMark)

Probably the natural next step is to extend this so that each constructor 'maps' to an unique URL

Joel McCracken

if that works, that sounds good!

Joel McCracken

but how would you make sure journalpage_entry is typesafe?

Sridhar Ratnakumar

(breadcrumbs are another feature this relates to)

Sridhar Ratnakumar

but how would you make sure journalpage_entry is typesafe?

what do you mean?

Joel McCracken

well if you "Probably the natural next step is to extend this so that each constructor 'maps' to an unique URL"

Joel McCracken

then you'll probably have something lik e

Joel McCracken

link (JournalPage_Entry "name of an entry")

Joel McCracken

i mean not exactly, but something lik ethis

Sridhar Ratnakumar

obelisk-route uses GADTs, so : JournalPage_Entry :: FilePath -> JournalPage (Source MMark) along those lines, I guess. I haven't fully thought about it yet.

Joel McCracken

sure, i guess what I amm saying is that in this case you need to cehck that the string is valid

Joel McCracken

if that's what you want to do

Joel McCracken

(just talking through the issues here =))

Sridhar Ratnakumar

obelisk uses universe to do this check

Sridhar Ratnakumar

I suspect if I'm to do it more properly it would involve extending the Source type and integrating it with a Route type somehow. It is in research phase right now.

Sridhar Ratnakumar

the way I am doing it now is that a single source basically defines a number of links that are avialable to it

How can one source have more than one link to it? Or do you mean the anchor links (<a id="foo" ...)?

Joel McCracken

yes, i mean anchor links

Joel McCracken

so like if i want to link to glossary.html#monoid

Joel McCracken

this ALSO is useful for making a "table of contents" for a page

Joel McCracken

BTW you can link against any ID

Joel McCracken

so if <div id="foobar">this is something great</div>

Joel McCracken

a great browser extension would be a thing that i can click

Joel McCracken

and will make it easy to link against anything on a page that has an ID

Joel McCracken

sometimes if i want to link to a specific part of an html page I will do this

Joel McCracken

inspect the element, see if it has an attached id