ramda.github.io icon indicating copy to clipboard operation
ramda.github.io copied to clipboard

Search by type signature

Open hackeryarn opened this issue 9 years ago • 19 comments

Would it be possible to incorporate type signature search in the current search bar. Something resembling Hoogle like functionality.

I would really like to be able to search for (a → b) → f a → f b and get map.

hackeryarn avatar Feb 18 '16 18:02 hackeryarn

This would be very nice indeed!

davidchambers avatar Feb 18 '16 19:02 davidchambers

agree 100% that would be nice.

buzzdecafe avatar Feb 18 '16 19:02 buzzdecafe

I agree. This would be very nice. I don't have a clue as to how to implement it, but I want it. I was talking about this just the other day.

If it were just text search, I think it would be easy enough, but it should be smart enough not to distinguish between (a -> b) -> [a] -> [b] and (c -> d) -> [c] -> [d], yet still recognize that while this is related, it's more specific: (x -> x) -> [x] -> [x].

Anyone have ideas?

CrossEye avatar Feb 19 '16 19:02 CrossEye

My only idea on this would be some tricky pattern matching or regexs.

Such as just checking that structure and ignoring the value names.

hackeryarn avatar Feb 19 '16 19:02 hackeryarn

couldn't we replace the current search/filtering with a nice js fuzzy search library?

davidchase avatar Feb 22 '16 03:02 davidchase

do you have one in mind?

buzzdecafe avatar Feb 22 '16 03:02 buzzdecafe

The ones ive played around with:

http://glench.github.io/fuzzyset.js/ http://kiro.me/projects/fuse.html

davidchase avatar Feb 22 '16 03:02 davidchase

I'm on the lookout for one for a work project too, although I haven't started actually looking yet. (I'm actually much more interested in solving that problem myself. It would be nice to do something algorithmically interesting for a change.)

CrossEye avatar Feb 22 '16 03:02 CrossEye

@CrossEye gotcha, maybe we can add something temporary and then switch it to something you've created... whatever works :smile:

davidchase avatar Feb 22 '16 03:02 davidchase

Ok, off to research the Bitap algorithm. Looks like fun.

CrossEye avatar Feb 22 '16 03:02 CrossEye

No, there's plenty of fun in Ramda; it's the day job that needs some sprucing up. It's also in a company with a long drawn-out approval process for third-party tools (not that we always tell them, but as this would be consumer-facing it might take some doing.) If I built my own there, there's no approval needed.

I'm all for trying to find a good tool for Ramda to use.

The trouble is that I think what we most want is a lot more tagging in order to search. It's not so much the fuzzy search, but the missing metadata. But I could be mistaken.

CrossEye avatar Feb 22 '16 03:02 CrossEye

The trouble is that I think what we most want is a lot more tagging in order to search.

In agreement here - more tags to group searches by would be excellent, and cater to a wider audience. However, fuzzy search on type signatures would definitely be a helpful addition too.

arcseldon avatar Feb 22 '16 03:02 arcseldon

makes sense, its probably just missing the signature in the filter code, i was just messing around with the libraries i mentioned above feeding them a data structure like which i scrapped from the DOM

...
  {
    "signature": "(a → a) → Number → [a] → [a]",
    "name": "adjust",
    "category": "List"
  },
  {
    "signature": "(a → Boolean) → [a] → Boolean",
    "name": "all",
    "category": "List"
  },
  {
    "signature": "[(*… → Boolean)] → (*… → Boolean)",
    "name": "allPass",
    "category": "Logic"
  },
  {
    "signature": "[a] → Boolean",
    "name": "allUniq",
    "category": "List"
  },
  {
    "signature": "a → (* → a)",
    "name": "always",
    "category": "Function"
  }
...

worked pretty well...

davidchase avatar Feb 22 '16 03:02 davidchase

The problem is that a good fuzzy type search seems much more sophisticated than a fuzzy text search. If we search Hoogle for (a -> b -> c) -> a -> [b] -> c, the results include for instance,

foldl :: (a -> b -> a) -> a -> [b] -> a
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]

but do not include

map :: (a -> b) -> [a] -> [b]

I'm not sure if text searches would be able to do that well.

i was just messing around with the libraries i mentioned above feeding them a data structure like which i scrapped from the DOM

...
  {
    "signature": "(a → a) → Number → [a] → [a]",
    "name": "adjust",
    "category": "List"
  },

Funny, I was playing around with something similar thinking about #1652, also scraped from the DOM, although I would hope to do it differently someday. Mine was an object grouped by category, and signature was a list. (See, for instance, init, last, nth.) But it's still much the same idea.

CrossEye avatar Feb 22 '16 14:02 CrossEye

I really like my new Alfred workflow for Ramda docs, which has baked in support for type signatures :smile: Here is an example usage off my desktop:

ramdasearch

I just choose the function I am looking for (in this example by type signature) and it takes me off to the required definition on ramdajs.

Thanks to raine for taking the effort to set this up. Think I even prefer it to the bash support.

arcseldon avatar Feb 22 '16 14:02 arcseldon

I've tried to implement some type driven search on http://ramda-search.now.sh It parses the signature to make some more educated search, but right now it doesn't yet implement the extended logic of https://github.com/ramda/ramda.github.io/issues/61#issuecomment-187207603

dawehner avatar Mar 17 '19 19:03 dawehner

@dawehner:

This looks like a very promising start. Is the code available somewhere?

CrossEye avatar Mar 17 '19 20:03 CrossEye

This week I will open a pull request for sanctuary-search, which will support type variable substitution as well as less fancy Hoogle features. The module will be used on the Sanctuary website; it may be a good fit for the Ramda website too.

davidchambers avatar Mar 17 '19 20:03 davidchambers

@CrossEye Thank you.I've implemented it here: https://github.com/dawehner/elm-ramda-search/blob/master/src/Main.elm it is in elm, feel free to ask questions if you want to know about it.

@davidchambers Interesting, I've never heard of sanctuary before, sorry :| I like the existence of Nothing for example! Looking forward to see how you implement the search.

dawehner avatar Mar 17 '19 21:03 dawehner