Don't think that will work because c is of type Maybe Square, not Maybe
Cell.

One further question - if I define

let null_square = { cell = Empty, num = 0 }

let get_square maybe_square =
  case maybe_cell of
    Nothing: null_square
    Just s : s

let get_letter maybe_square =
  case maybe_square of
    { Letter s } -> s
    _ -> ""

would that be introducing an inefficient creation of a null_square every
time I call get_letter or is it just a cheap reference?

martin

On Fri, Sep 23, 2016 at 12:04 PM, Simon <[email protected]> wrote:

> This should work
>
>  case c of
>     Just (Letter s) ->
>       s
>     _ -> ""
>
>
>
> On Friday, 23 September 2016 03:50:19 UTC+2, Martin DeMello wrote:
>>
>> If I have the following code:
>>
>> type Cell = Empty | Letter String
>>
>> type alias Square =
>>   { cell : Cell
>>   , num : Int
>>   }
>>
>> and c : Maybe Square,
>>
>> can I do the following in a single match?
>>
>>   case c of
>>     Just { cell } ->
>>       case cell of
>>         Letter s -> s
>>         _ -> ""
>>     _ -> ""
>>
>> that is, i conceptually want
>>
>>   case c of
>>     Just { cell = Letter s } -> s
>>     _ -> ""
>>
>> martin
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to