title: Right way to forcibly convert Maybe a to a in Elm, failing clearly for Nothings
body: <p>Okay, what I really wanted to do is, I have an Array and I want to  choose a random element from it. The obvious thing to do is get an integer from a random number generator between 0 and the length minus 1, which I have working already, and then applying <a href="http://package.elm-lang.org/packages/elm-lang/core/1.1.1/Array#get" rel="noreferrer">Array.get</a>, but that returns a <code>Maybe a</code>. (It appears there's also a <a href="http://package.elm-lang.org/packages/mgold/Elm-Random-Sampling/2.0.1/Random-Array#sample" rel="noreferrer">package function that does the same thing</a>.) Coming from Haskell, I get the type significance that it's protecting me from the case where my index was out of range, but I have control over the index and don't expect that to happen, so I'd just like to <strong>assume I got a <code>Just</code> something and somewhat forcibly convert to <code>a</code>.</strong> In Haskell this would be <code>fromJust</code> or, if I was feeling verbose, <code>fromMaybe (error "some message")</code>. <strong>How should I do this in Elm?</strong></p>
  
  <p>I found <a href="http://comments.gmane.org/gmane.comp.lang.elm.general/4377" rel="noreferrer">a discussion on the mailing list</a> that seems to be discussing this, but it's been a while and I don't see the function I want in the standard library where the discussion suggests it would be.</p>
  
  <p>Here are some pretty unsatisfying potential solutions I found so far:</p>
  
  <ul>
  <li>Just use <a href="http://package.elm-lang.org/packages/elm-lang/core/1.1.1/Maybe#withDefault" rel="noreferrer">withDefault</a>. I do have a default value of <code>a</code> available, but I don't like this as it gives the completely wrong meaning to my code and will probably make debugging harder down the road.</li>
  <li>Do some fiddling with ports to interface with Javascript and get an exception thrown there if it's Nothing. I haven't carefully investigated how this works yet, but apparently it's possible. But this just seems to mix up too many dependencies for what would otherwise be simple pure Elm.</li>
  </ul>