implementation 2017-02-17 11:45:08
there is no single function, there is a whole family of functions, one for each instance of the Exception typeclass
ezyang 2017-02-17 11:45:24
oh, actually, it does use Typeable \o/
ezyang 2017-02-17 11:45:30
fromException (SomeException e) = cast e is the magic
implementation 2017-02-17 11:46:02
where do you see that?
`Guest05 2017-02-17 11:46:32
so..
monochrom 2017-02-17 11:46:34
ezyang: It is possible that the default locale dislikes certain non-ASCII characters. chcp 65001 to ensure UTF-8.
`Guest05 2017-02-17 11:47:01
if i do it exactly as in source for fromException
`Guest05 2017-02-17 11:47:07
by defining a function
monochrom 2017-02-17 11:47:08
There are also per-handle functions to just set this per handle.
`Guest05 2017-02-17 11:47:10
it works
`Guest05 2017-02-17 11:47:21
but if i make a lambda or a case
ezyang 2017-02-17 11:47:22
monochrom: Hmm
mniip 2017-02-17 11:47:31
SomeException stores the Typeable instance of the type
ezyang 2017-02-17 11:47:33
ok, I'll give that a try
`Guest05 2017-02-17 11:47:42
it complains about "(rigid,skolem)"s
monochrom 2017-02-17 11:47:42
`Guest05, the intention is that you don't implement your own fromException, you just use the default, i.e., you write no code.
mniip 2017-02-17 11:47:43
so that you don't impose a restriction on a skolem tyvar
mniip 2017-02-17 11:47:58
but still can derive type information and the validity of a cast from the Typeable dictionary
monochrom 2017-02-17 11:48:19
But if you do need to write custom code for whatever reason, you will need to know existential types.
ezyang 2017-02-17 11:48:24
but I'm pretty sure there are no non-ASCII characters in my output
`Guest05 2017-02-17 11:48:24
monochrom: hackage documentation says that i do implement fromException if i want to make hierarchy
monochrom 2017-02-17 11:48:50
Yes but it is unusual to want a hierarchy. Even the OOP people are growing out of it.
`Guest05 2017-02-17 11:49:21
i want to make assertions with user messages and have catchable AssertFailed...
ezyang 2017-02-17 11:49:50
oooh, I didn't even realize that we could define hierarchies!
monochrom 2017-02-17 11:49:55
5 hours of abstract hierarchy can be saved by 5 minutes of sum type.
monochrom 2017-02-17 11:50:22
Take for example AsyncException.
ezyang 2017-02-17 11:50:48
If I want to create an exception that masquerades as an IOException can I do it with the hierarchy mechanisms?
MarcelineVQ 2017-02-17 11:51:06
is the only way to distinguish between 'too many open files' and 'device is out of space' with an IOException of ioe_type ResourceExhausted to examine the ioe_description string? worded more directly, or if that string doesn't contain that info, how can I discern between the two?
monochrom 2017-02-17 11:51:18
No, you need a type class first.
ezyang 2017-02-17 11:51:25
:(
ezyang 2017-02-17 11:51:55
MarcelineVQ: If you look under the covers of IOException there are a number of fields that you can access via functions
monochrom 2017-02-17 11:51:59
Actually let me double-check.
ezyang 2017-02-17 11:52:00
If all of them are the same you're outta luck
monochrom 2017-02-17 11:52:37
Yeah you need a type class first.
ezyang 2017-02-17 11:52:45
Sigh
MarcelineVQ 2017-02-17 11:52:46
yes, I've yet to investigate fully, but the pretty printed error is distinct for the two so I wanted to ask ahead of exploring to see if there was something common
ezyang 2017-02-17 11:53:12
the relevant info should be squirreled away in one of the other fields
monochrom 2017-02-17 11:53:17
But why masquerade as IOException when you can masquerade as SomeException :)
ezyang 2017-02-17 11:53:45
monochrom: Because some end user who I don't have control over used catchIO and now I am sad
monochrom 2017-02-17 11:54:58
Approximately you have to use the String argument of userError.
ezyang 2017-02-17 11:55:30
yeah, that's what we ended up doing
jle` 2017-02-17 11:55:35
ezyang: (error "hey" :: IOException)
jle` 2017-02-17 11:55:37
hehe
MarcelineVQ 2017-02-17 11:55:38
ezyang: mostly I was hoping for something other than english language strings to be basing my error classifying off of :>
monochrom 2017-02-17 11:55:46
Put Gödel numbering in the string so your catcher can decode it and find a whole hierarchy.
MarcelineVQ 2017-02-17 11:55:47
does anyone know if errno here http://hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.IO.Exception.html#IOException is well defined anywhere?
`Guest05 2017-02-17 11:55:58
* My brain just exploded
`Guest05 2017-02-17 11:55:58
I can't handle pattern bindings for existential or GADT data constructors.
ezyang 2017-02-17 11:56:00
There should be errnos
`Guest05 2017-02-17 11:56:17
what a wording...
ezyang 2017-02-17 11:56:21
`Guest05: don't let-bind: case
monochrom 2017-02-17 11:56:22
Unfortunately no errnos for the Windows people.
`Guest05 2017-02-17 11:56:23
i was startled
monochrom 2017-02-17 11:56:57
Double negative elimination: errnono -> err
monochrom 2017-02-17 11:58:46
`Guest05: See how this is a whole rabbit hole right inside a pandora box. Is it simpler to just use a sum type?
mniip 2017-02-17 11:58:55
wait
mniip 2017-02-17 11:59:01
you can't let-bind gadts?
monochrom 2017-02-17 11:59:07
Right.
mniip 2017-02-17 11:59:16
oh I suppose that might be a problem with recursive bindings?
monochrom 2017-02-17 11:59:31
I don't actually know the issue.
MarcelineVQ 2017-02-17 11:59:47
ezyang, monochrom: thank you for your responses
monochrom 2017-02-17 11:59:54
Somewhere on the GHC trac someone may have discussed it.
`Guest05 2017-02-17 12:00:27
monochrom: how do i make assertions with user messages convertible to AssertionFailed with sum types?
jle` 2017-02-17 12:00:27
maybe it has to do with let polymorphism
mniip 2017-02-17 12:00:37
maybe it's maybelline
monochrom 2017-02-17 12:01:05
:)
MarcelineVQ 2017-02-17 12:01:26
maybe it's read, maybe it's haskeline
monochrom 2017-02-17 12:01:39
haha great
monochrom 2017-02-17 12:04:29
Either use AssertionFailed directly (via "assert"), or forget AssertionFailed altogether and just write your own type.
monochrom 2017-02-17 12:04:40
Conversion is a lost cause.
monochrom 2017-02-17 12:05:11
Two cases:
monochrom 2017-02-17 12:06:00
Either the user uses "assert", which will not use the hierarchy you endeavoured to build.
monochrom 2017-02-17 12:06:35
Or the user uses your hierarchy and your nice thrower functions, in which case why invite AssertionFailed to the party?
monochrom 2017-02-17 12:07:00
The thing is so-called "conversion" will have to lose the user message you have.
`Guest05 2017-02-17 12:07:24
i don't know
`Guest05 2017-02-17 12:07:30
i just waant it, it seems nice
`Guest05 2017-02-17 12:07:33
want *
`Guest05 2017-02-17 12:11:22
poor AssertionFailed, it wasn't invited
monochrom 2017-02-17 12:20:45
Re: pattern bindings and GADTs. "The reason for this restriction is really an implementation one. Type-checking binding groups is already a nightmare without existentials complicating the picture. Also an existential pattern binding at the top level of a module doesn't make sense, because it's not clear how to prevent the existentially-quantified type "escaping". So for now, there's a simple-to-state restriction. We'll see how
monochrom 2017-02-17 12:20:45
annoying it is."
buttons840 2017-02-17 12:24:36
in ghci I will do `let f = 'x'` but then whenever I do `:r` all my let bindings are gone from ghci; is there a way to avoid this?
dolio 2017-02-17 12:26:21
EvanR: That talk was pretty awesome.
dolio 2017-02-17 12:27:43
As an IEEE754 hater, at least.
EvanR_ 2017-02-17 12:29:48
i am somewhat more convinced now that the unum guy is not a crackpot
monochrom 2017-02-17 12:31:01
err, s/GADTs/existential/
monochrom 2017-02-17 12:32:12
buttons840: Put it in a file, and :r that file.
dolio 2017-02-17 12:33:18
There are non-typechecking reasons.