String to Hash ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

String to Hash ?

raptor@tvskat.net
I have made a simple Split function, here is how it works :

str = "k1=v1|k2=v2|k3=v3"

> map (sSplit '=') (sSplit '|' str)
[["k1","v1"],["k2","v2"],["k3","v3"]]

Now what I want to do is to return listOfPairs (instead listOflists) so that I can
give this as parameter to Data.Map.fromList and build hash-like structure.
What would be the easiest way ?


PS. Can anyone point me to a source/link where I can see more examples
of using Hash-like structures ?
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: String to Hash ?

Ben Franksen-2
On Thursday 08 December 2005 15:03, raptor wrote:

> I have made a simple Split function, here is how it works :
>
> str = "k1=v1|k2=v2|k3=v3"
>
> > map (sSplit '=') (sSplit '|' str)
>
> [["k1","v1"],["k2","v2"],["k3","v3"]]
>
> Now what I want to do is to return listOfPairs (instead listOflists)
> so that I can give this as parameter to Data.Map.fromList and build
> hash-like structure. What would be the easiest way ?

Write a function:

list_to_pair :: [a] -> (a,a)

and then map it over the list of lists:

map list_to_pair your_resulting_list_of_lists

HTH,
Ben
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: String to Hash ?

raptor@tvskat.net
Is there in standard libraries functions that do
structure transformations ?
just curious...

|Write a function:
|
|list_to_pair :: [a] -> (a,a)
|
|and then map it over the list of lists:
|
|map list_to_pair your_resulting_list_of_lists
|
|HTH,
|Ben
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: String to Hash ?

Cale Gibbard
Not this one in particular, but there are various functions throughout
the libraries which do all sorts of structural transformations on
lists and other types. Have a look at the Prelude and Data.List module
in the libraries documentation at
http://www.haskell.org/ghc/docs/latest/html/libraries/

listToPair is probably not worth giving a name to, as it's so specific
(it only works on lists of length 2) and such a short lambda term
anyway.

 - Cale

On 08/12/05, raptor <[hidden email]> wrote:

> Is there in standard libraries functions that do
> structure transformations ?
> just curious...
>
> |Write a function:
> |
> |list_to_pair :: [a] -> (a,a)
> |
> |and then map it over the list of lists:
> |
> |map list_to_pair your_resulting_list_of_lists
> |
> |HTH,
> |Ben
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe