Ah yes this makes sense, we'd need the explicit type annotation. Has that 
functionality been discussed? I know I saw a talk where Evan mentioned 
adding features to the language over time intentionally to help drive 
adoption.

Thanks!

On Monday, January 16, 2017 at 9:06:50 PM UTC-5, Nick H wrote:
>
> I doubt such a function will be introduced any time soon, because it's not 
> a properly typed operation. In Haskell, you have to add the type annotation 
> to the function call because read's return type is ambiguous. However, Elm 
> doesn't have any similar ability.
>
> For converting Strings to numeric types, there are String.toInt and 
> String.toFloat.
>
> For doing what your example does, I might consider using a dictionary 
> mapping strings to states. Maybe Something like:
>
> viewStates = Dict.fromList [ ("ViewDocList", ViewDocList), 
> ("ViewDocument", ViewDocument) ]
>
> locationUpdate location =
>   case Dict.get location viewStates of
>     Just state ->
>       ViewState state
>
>     Nothing -> 
>       App.NoOp
>
> You still need to manually associate strings with view states, but now 
> locationUpdate has the form you want.
>
> On Mon, Jan 16, 2017 at 12:44 PM, Josh Szmajda <jos...@gmail.com 
> <javascript:>> wrote:
>
>> Hey folks!
>>
>> This is in reference to https://github.com/elm-lang/core/issues/805
>>
>> I'm looking for a function to convert a String to an internal symbol 
>> (signature `String -> a`). Previously this was in `Text.fromString` but 
>> apparently that has been removed.
>>
>> The use-case I have in mind is this router:
>>
>> ```
>> locationUpdate : Navigation.Location -> App.Msg
>> locationUpdate location =
>>   case (String.dropLeft 2 location.hash) of
>>
>>     "ViewDocList" -> ViewState ViewDocList
>>
>>     "ViewDocument" -> ViewState ViewDocument
>>
>>     _ -> App.NoOp
>>
>>     -- Would rather code this as:
>>     -- case Text.fromString msg of
>>     --   Just value -> ViewState value
>>     --   Nothing    -> App.NoOp
>> ```
>>
>> In Haskell this would be `read`:
>>
>> ```
>> Prelude> read "4.5" :: Float
>> 4.5
>> Prelude> :t read "4.5" :: Float
>> read "4.5" :: Float :: Float
>> ```
>>
>> Any ideas on when this might come back?
>>
>> Thanks!
>> -Josh
>>
>> -- 
>> 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 elm-discuss...@googlegroups.com <javascript:>.
>> 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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to