mwotton / Hubris

Bridge from Ruby to Haskell
shimweasel.com
260 stars 16 forks source link

Tuple support #16

Closed larrytheliquid closed 13 years ago

larrytheliquid commented 14 years ago

Not sure what the ideal api would be here... maybe just: class Hubris::Tuple < Array def initialize(_args) super([_args]) end def inspect() super.gsub!('[', '(').gsub(']', ')') end end So: class Tupler hubris :inline => "idTuple :: (Integer, Char) -> (Integer, Char) ; idTuple x = x" end

Tupler.new.idTuple(Hubris::Tuple.new(1, 'a')) # => (1, 'a')
mwotton commented 14 years ago

I don't like that interface much. I think it should be possible to do it all on the Haskell side - you'd just need to provide instances for Haskellable and Rubyable for each of the sizes of tuple you were interested in - perhaps some Template Haskell could make that less repetitive. I think the real problem is that there's currently no way to inject new instances into the scanning stage.

mwotton commented 14 years ago

so, to clarify, this use case ought to work

class Foo
  hubris :inline => "tupler (a,b) = (b,a)"
  hubris :inline => "doubler l = map (2*) "
end

f=Foo.new
f.tupler([1,2])
=> [2,1]
f.doubler([1,2])
=> [2,4]

so it'd be all arrays on the ruby side.

larrytheliquid commented 14 years ago

i think that'll work. i was worried about array being used for both tuples and lists in the nested cases, but in hindsight the haskell side will just work with whatever type it ended up declaring

mwotton commented 14 years ago

yeah, that's the theory. should really come up with some twisted test cases though.

mwotton commented 13 years ago

ok, I think this is working, at least on https://ci.shimweasel.com.