-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Sudoku solver #10
base: master
Are you sure you want to change the base?
Conversation
Yes lots of unsupported/not implemented apis here. In general FSharp.Core is patchily implemented and I wasn't planning on even attempting to support System.* as it is very OO / imperative. I'd suggest you rewrite it in a more functional style using only the standard fsharp library. There is no benefit with using stuff like |
n * count + m | ||
|
||
let boxes (sudoku:Sudoku) = | ||
let d = sudoku |> Array.length |> float |> System.Math.Sqrt |> int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of System.Math.Sqrt
we can implement sqrt
in Microsoft.FSharp.Core.Operators.erl
(or whereever that lives in FSharp.Core).
let start = System.DateTime.Now | ||
let solution = getFirstSolution sudoku | ||
|
||
printfn "%As" <| System.Math.Round((System.DateTime.Now - start).TotalSeconds,2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of System.DateTime
use interop to call the erlang equivalent (erlang:system_time/1
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively you could try creating an erlang module named System.erl
with a DateTime.Now/0
function in it. That might work as well as fez will translate calls in that way. (check .core output for what it actually worked out).
One of the really really great things about fable is that it replaces all such things and the Sudoku solver just works in Javascript. My personal dream would be that I can take my domain model code und just compile it to beam. Without mapping all the apis manually. I know that's a very long way. But that would be a nice goal. |
Unfortunately, f# is a second class citizen on its native platform, common
actions like type-casting throw exceptions instead of using option/either
types.
And the OOP is pervasive.
I was looking into implementing Char, Regex and Match but it would need to
support some of the methods that they inherit from the c# Object hierarchy
downwards.
…-- Siddarth
On 18-Jun-2017 2:14 AM, "Steffen Forkmann" ***@***.***> wrote:
One of the really really great things about fable is that it replaces all
such things and the Sudoku solver just works in Javascript.
My personal dream would be that I can take my domain model code und just
compile it to beam. Without mapping all the apis manually. I know that's a
very long way. But that would be a nice goal.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#10 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHxDp-8wJkLUyeY1SgvCJCJG04J2pWO6ks5sFDq2gaJpZM4N9S2D>
.
|
Well we'll see how far we can take it but I could imagine System being supported through a separate library with System modules being implemented in erlang. Still mutation will be an issue here as well but simple static methods would work ok. |
@alfonsogarciacaro could you please comment a bit a out how fable deals with this? Or give some pointers? Thx |
The Fable compatibility docs are what I've been looking at, you might find
some answers there.
https://fable-compiler.github.io/docs/compatibility.html
If we can gain parity with those, we'd be in a good place I think.
…On Sun, Jun 18, 2017 at 2:13 PM, Steffen Forkmann ***@***.***> wrote:
Reopened #10 <#10>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#10 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AHxDpxyn6M3LL6QeM4YKAD8AVzQvhahKks5sFOMagaJpZM4N9S2D>
.
|
Yes fable doesn't support every api in the BCL. But enough to be super useful and to basically allow me to transpile our complete domain model without rewrites. |
The problem will always be mutation. Supporting the non mutable subset
would be possible but ideally as a separate optional set of erlang modules.
…On Sun, 18 Jun 2017 at 10:36, Steffen Forkmann ***@***.***> wrote:
@alfonsogarciacaro <https://github.com/alfonsogarciacaro> could you
please comment a bit a out how fable deals with this? Or give some
pointers? Thx
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#10 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABIDlP52Y1lrOkhucUezVtaMmfq-T78Uks5sFOMYgaJpZM4N9S2D>
.
|
Yes, we probably need to change how we approach the problems a bit. Makes it more interesting 😄 |
Just to make this super clear. My problem is not to write a Sudoku solver. This is just some random snippet. My interest is to use existing domain code and run it in things like Phoenix. This would allow me to use the same domain logic in my Javascript clients, my suave app and if needed I can port it to a different platform when I have good reasons for that |
And that will be possible the more functional your approach is. Sure we can
probably rewrite imperative code using recursion. We may even be able to
support local mutable fields using the process dictionary but the benefits
would be scant and it may lead users to the wrong conclusions (e.g.
Mutation is faster). Wouldn't it be better to focus on supporting the
paradigm that works best? I'm not saying it's off the table only lower down
on priorities.
…On Sun, 18 Jun 2017 at 11:36, Steffen Forkmann ***@***.***> wrote:
Just to make this super clear. My problem is not to write a Sudoku solver.
This is just some random snippet.
My interest is to use existing domain code and run it in things like
Phoenix. This would allow me to use the same domain logic in my Javascript
clients, my suave app and if needed I can port it to a different platform
when I have good reasons for that
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#10 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABIDlOZtmQnslEH0jzKuRCmSbOsXQepmks5sFP2wgaJpZM4N9S2D>
.
|
Absolutely. Tbh my domain models don't really have mutable state. I'm just
saying if we support basic things like dictionaries, list, array and so on
then it would be great
Am 18.06.2017 12:51 nachm. schrieb "Karl Nilsson" <notifications@github.com
…:
And that will be possible the more functional your approach is. Sure we can
probably rewrite imperative code using recursion. We may even be able to
support local mutable fields using the process dictionary but the benefits
would be scant and it may lead users to the wrong conclusions (e.g.
Mutation is faster). Wouldn't it be better to focus on supporting the
paradigm that works best? I'm not saying it's off the table only lower down
on priorities.
On Sun, 18 Jun 2017 at 11:36, Steffen Forkmann ***@***.***>
wrote:
> Just to make this super clear. My problem is not to write a Sudoku
solver.
> This is just some random snippet.
>
> My interest is to use existing domain code and run it in things like
> Phoenix. This would allow me to use the same domain logic in my
Javascript
> clients, my suave app and if needed I can port it to a different platform
> when I have good reasons for that
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <#10 (comment)>, or
mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/
ABIDlOZtmQnslEH0jzKuRCmSbOsXQepmks5sFP2wgaJpZM4N9S2D>
> .
>
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#10 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADgNH6X3f2YK4A_Z9VK548Wt-SweVDJks5sFQEvgaJpZM4N9S2D>
.
|
sorry if the following is completely stupid. Can we use ETS tables to emulate Lists and dictionaries? https://elixir-lang.org/getting-started/mix-otp/ets.html Maybe something along the lines of:
Maybe this is not the nicest thing on earth, but could it work? as a first hacky version? |
I think its doable with some caveats. ets is a bit tricky, the table-names are global to all processes. And the table exists till the parent process gets killed, or the table is sent a delete message. There also seems to be a upper limit on number of tables per erlang node(around 1400 by default). This seems like a good idea to get around some of the places where it is impossible to do things immutably. Although having a nice f#ish wrapper around ets for in-memory storage would be fantastic!! |
it was an idea to get things started. maybe someone can implement it and later we improve on it |
ok I was playing with this earlier and accidentally committed er ETS - they don't have to be named but it may be better to use the process dictionary to implement |
I hacked up a potential process dictionary backed |
after applying #9 I tried to compile my sudoku solver. but no luck: