faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 86 forks source link

Issue with type = ... and pattern matching #380

Closed geraldus closed 10 years ago

geraldus commented 10 years ago

Hello buddies! Sorry if I stupid and annoying. Consider following code, which works:

I have small helper:

fromNullable :: Nullable a -> a
fromNullable (Nullable smth) = smth

Every time before I use it I must be sure if value is not Null. That's not big deal.

snap :: String -> Fay (Nullable Fragment)
snap = ffi "Snap(%1);"

When I snaping back a real object but not Null then it is OK to pass the result to fromNullable and unwrap Fragment.

Then I wanted to make my code a bit cleaner and finished with this:

type NullFragment = Nullable Fragment
snap :: String -> Fay NullFragment

But this time I'm getting a runtime exception unfortunately, because in this case I could not pattern match (Nullable smth) anymore.

Uncaught unhandled case in fromNullable

Is this a bug or just another not implemented feature?

bergmark commented 10 years ago

Resolving type aliases in the FFI hasn't been implemented yet, #185.

On Thu, Jan 9, 2014 at 11:04 PM, Артур Файзрахманов < notifications@github.com> wrote:

Hello buddies! Sorry if I stupid and annoying. Consider following code, which works:

I have small helper:

fromNullable :: Nullable a -> a fromNullable (Nullable smth) = smth

Every time before I use it I must be sure if value is not Null. That's not big deal.

snap :: String -> Fay (Nullable Fragment) snap = ffi "Snap(%1);"

When I snaping back a real object but not Null then it is OK to pass the result to fromNullable and unwrap Fragment.

Then I wanted to make my code a bit cleaner and finished with this:

type NullFragment = Nullable Fragment snap :: String -> Fay NullFragment

But this time I'm getting a runtime exception unfortunately, because in this case I could not pattern match (Nullable smth) anymore.

Uncaught unhandled case in fromNullable

Is this a bug or just another not implemented feature?

— Reply to this email directly or view it on GitHubhttps://github.com/faylang/fay/issues/380 .

bergmark commented 10 years ago

I'll close this in favor of that ticket, please subscribe to that one for updates.