frp - Pattern match on chars -


im pretty new elm (elm-server 0.9.2), , have encountered problem has become quite obstacle me.

here problem:

according version-0.9 documentation should able write:

stripcommas str =   case str of     ',' :: rest -> stripcommas rest     c   :: rest ->  c  :: stripcommas rest 

so test did own function (quite similar :) ):

stripnewline str =    case str of    '\n' :: rest -> stripnewline rest     c   :: rest ->  c  :: stripnewline rest 

but booth of them fails, after debugging notice in javascript:

var stripnewline = function(str){     return function(){       switch (str.ctor) {         case '::':           switch (str._0) {             case chr '\n':               return stripnewline(str._1);           }           return _l.cons(str._0,stripnewline(str._1));       }_e.case($modulename,'between lines 22 , 33')}();}; 

i don't know javascript seems chr '\n' should chr('\n'), tough might wrong...can point me in right direction here cause im lost...

it elm bug – has been fixed since latest stable release – , you're right, it's wrongly generated javascript.

additionally, there's logic problem in example code you're copying announcement blog post, it's doing non-exhaustive pattern match.

strings lists of chars (i.e. string [char]), proper pattern match should handle empty list case, i.e:

stripcommas str =   case str of     []          -> str     ',' :: rest -> stripcommas rest     c   :: rest ->  c  :: stripcommas rest  main = astext <| stripcommas "1,2,3,4,5" 

you can test here (select "master/head" version options, later version current release has js generation bug).


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -