I'm forced to work on a project that has a lot of java code, but i'd like to remain true to haskell. The reasons for this are multitude and i won't really bore you with them.
Is there something in the wild that already takes haskell code and generate java code ?
I'd appreciate any and all advice!
Edit: i'd like to TRANSLATE the code, not run it in the JVM - I know Jaskell exists, but it's not what i'm looking for.submitted by shokodemon
[link] [21 comments]
The "four fours" is an interesting mathematical puzzle: "Given 4 instances of the digit "4", represent all integers using mathematical symbols and operators in common use." The symbols and the way of combining the fours vary from version to version of the puzzle (sometimes .4 is allowed, or the power operator).
I was thinking that it would be fun to solve it in haskell, generating all possible solutions and taking the first n. But that took me to one interesting question: is there a way to generate a lazy list of all possible values of an algebraic data type?
In my idea I would have:data Fours = F | FF | FFF | FFFF
to represent 4, 44, 444 and 4444. You can easily add .4, .44, .444 and .4444. Then the auxiliary functionsdigits :: Fours -> Double digits F = 1 .... value :: Fours -> Double value F = 4 ...
(Of course, there could be more interesting representations, like (Four Int Int) indicating the number of fours before and after the decimal point, but I am more interested in a type with a finite number of values).
And the expression type:data Expr = Num Fours | Sum Expr Expr | Rest Expr Expr | Mul Expr Expr | Div Expr Expr | Fact Expr | Sqrt Expr eval :: Expr -> Double eval Num a = Value a ...
Now, if I were able to get a list of all possible Expr, I would filter those who have exactly four fours, sort by its value and voila! But I guess that would imply to construct a non-trivial map from Int -> Expr. I'm looking for an elegant way to get all possible answers.submitted by mvaliente2001
[link] [9 comments]