Question

I need to create a function f:: Log->[String] that does that (((o, i ,d),s) = [(o, i ,d)]

type Log = (Plate, [String])

type Plate = (Pin, Pin, Pin) type Pin = (Char, Int)

Was it helpful?

Solution

g :: Log -> [String]
g (plate, _) = [show plate]

OTHER TIPS

If you're on a page like this, click "Source" on the fir right side, next to the function that you're interested in.

If you need to look up a function, Hayoo! and Hoogle will link you to documentation pages like the one above.

An important thing to note, though is that show doesn't have one definition. show is a function defined for all data types in the Show (with a capital "S") typeclass. So for example, here is the full source for the Show typeclass. Show is defined within the typeclass as just show :: a -> String. But if you search for "instance Show Bool" or "instance Show Int", you'll find specific definitions.


For the second part of your question, the easiest way to get a show function for a new type is to simply write deriving (Show) below it. For example,

data Foo = Foo Int Int
   deriving (Show)

Now I can use show on data with type Foo.

Use hoogle to find this sort of information.

Example: http://www.haskell.org/hoogle/?hoogle=show

Once you've found the function you'd like in the list, click and there you'll find a Source link on the right hand side of the page.

NB this is an answer to the original question:

Where can I see the codes of the predefined functions in haskell ?? Mainly the function SHOW?

It's true that you can use Hoogle to search for functions defined in the Prelude (and other modules), but the source code itself is located at Hackage.

Hackage is a database of Haskell packages. You can download new packages from it, and also view the Haddock documentation for every package in the database.

This is the Haddock page for the standard Prelude. It documents the type classes, data types, types, and top-level functions exported by the Prelude module. To the right of each definition header is a link that says "Source". You can click this to be taken to an online copy of the source code for the module you're viewing.


On preview, you're now asking a different question entirely, and on preview again in fact the original question has been edited out of this post.

Your new question is unclear, but this solution will work to produce the output in your example.

> [fst ((('O',0),('I',0),('D',1)),"O->D")]
[(('O',0),('I',0),('D',1))]

I think you're using list notation instead of double quotes to identify Strings, by the way, so I fixed that around 0->D above. So you might also try this instead.

> show (fst ((('O',0),('I',0),('D',1)),"O->D"))
"(('O',0),('I',0),('D',1))"

This works because you have only defined type synonyms (by using type in your declarations instead of data) on data structures which already have Show instances.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top