ramda / ramda.github.io

:ram: :globe_with_meridians: Documentation for Ramda.js
http://ramdajs.com
58 stars 71 forks source link

Search by type signature #61

Open hackeryarn opened 8 years ago

hackeryarn commented 8 years ago

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.

davidchambers commented 8 years ago

This would be very nice indeed!

buzzdecafe commented 8 years ago

agree 100% that would be nice.

CrossEye commented 8 years ago

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?

hackeryarn commented 8 years ago

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

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

davidchase commented 8 years ago

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

buzzdecafe commented 8 years ago

do you have one in mind?

davidchase commented 8 years ago

The ones ive played around with:

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

CrossEye commented 8 years ago

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.)

davidchase commented 8 years ago

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

CrossEye commented 8 years ago

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

CrossEye commented 8 years ago

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.

arcseldon commented 8 years ago

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.

davidchase commented 8 years ago

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...

CrossEye commented 8 years ago

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.

arcseldon commented 8 years ago

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.

dawehner commented 5 years ago

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

CrossEye commented 5 years ago

@dawehner:

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

davidchambers commented 5 years ago

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.

dawehner commented 5 years ago

@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.