Author Hjulle
 Title Illustrate fibs
 Created at Sun Apr 12 14:14:15 UTC 2015
 Parent paste  #2507
{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
import Diagrams.TwoD.Text

example = (labeled "asdf qeq fibs:" $ squaredList (fibs))
          ===
          (labeled "tail fibs:" $ squaredList (tail fibs))


squaredList xs = hcat (map showSquared $ take 6 xs) ||| (rect 2 1 `atop` text "...")

showSquared :: Show a => a -> Diagram B R2
showSquared = squared . show

squared :: String -> Diagram B R2
squared x = (square 1 :: Diagram B R2) <> text x


labeled :: String -> Diagram B R2 -> Diagram B R2
labeled x =  (txt |||)
 where
   fnted = txt # fontSize 0.5
   txt =  (rect 6 1  :: Diagram B R2) <> alignedText 0.1 0.5 x 

fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
Result
...853211tail fibs:...532110asdf qeq fibs:
Warning
The import of ‛Diagrams.TwoD.Text’ is redundant
except perhaps to import instances from ‛Diagrams.TwoD.Text’
To import instances alone, use: import Diagrams.TwoD.Text()
Warning
Top-level binding with no type signature: example :: Diagram B R2
Warning
Top-level binding with no type signature:
squaredList :: forall a. Show a => [a] -> Diagram B R2
Warning
Defined but not used: ‛fnted’